fi en

Three Cool Things about Ruby

26 Feb 2018 by Tuomas Jomppanen

If you would like to star as a guest writer on Talented blog and share your knowledge on the (tech)topic of your choice, tell us at

Ruby was created in 1993 by Yukihiro Matsumoto (Matz). It’s a programming language that was designed to maximize programmers’ happiness.
Ruby is a language where term “flexible syntax” gets a new meaning. It’s a dynamically typed object-oriented language with a really loose syntax, so it can be bent further than the spoon in Matrix movie trilogy.


Ruby has a specific way for defining a code block. You can use do and end or { } to define a block.

["Teemu", "Paul", "Wayne"].each do |name|
puts "#{name} scores!"

The code inside the block is run only if creates the file successfully.“basic_rules_of_secret_societies.txt”, “w”) do |file|
file.puts("1. Talented is building a secret society of experienced programmers")
file.puts("2. Goto 10")

You can call a block from a function.

class Person
attr_accessor :name, :email, :role
def initialize(role = :visitor)
self.role = role
end do |person| = “Tuomas” = “tuomas@localhost”
end=> #<Person:0x007ffe660fa980 @name=”Tuomas”, @email=”tuomas@localhost” @role=:visitor>



arr = ["Tuomas", "Maria", "Teemu", "Jasmin"]
reversed = { |s| s.reverse }
=> ["samouT", "airaM", "umeeT", "nimsaJ"]
secret_password = reversed.join()
=> "samouTairaMumeeTnimsaJ"

Filtering data structures without any side effects.

frameworks = {
"Ruby": ["Ruby on Rails", "Sinatra"],
"JavaScript": ["Express"],
"Python": ["Flask", "Django"]
# longer version do |key, values|
values.count > 1
=> {:Ruby=>[“Ruby on Rails”, “Sinatra”], :Python=>[“Flask”, “Django”]}# shorter version {|k,v| v.count > 1}
=> {:Ruby=>[“Ruby on Rails”, “Sinatra”], :Python=>[“Flask”, “Django”]}



if user.last_activity_at > 10.days.ago

Number is an object and it can have methods.

irb(main):001:0> 3.class
=> Fixnum
irb(main):002:0> 3.to_s
=> "3"
irb(main):003:0> 3.to_f
=> 3.0


Software industry insights to your inbox?

Sign up for our newsletter and stay up to date what the software industry is puffing about! You’ll also receive occasional tips and tricks for job hunting and entrepreneurship.

Company representative, sign up for industry insights here →.

By entering your email address you agree to receive our newsletter on a monthly basis in accordance with our Privacy Policy →