Edgar Latorre

I'm Edgar and this is my blog where I write about software development.

Nice Stuff In Ruby 2.0

12 Jun 2013

Today I’ll write about new stuff in ruby that I think is nice.

Now the ruby changed the default unicode to utf-8:

puts __ENCODING__
UTF-8


The Ruby 2.0 has a new literal to create array of symbols:

array_of_symbols = %i[one two three]
=> [:one, :two, :three]


Keyword arguments:

def my_args(**keywords)
  keywords
end

my_args(name:'edgar')
=> {:name=>"edgar"}


New convention for conversion to hash:

Band = Struct.new(:name, :style)
band = Band.new('Stray Cats', 'Rockabilly')

band.to_h
=> {:name=>"Stray Cats", :style=>"Rockabilly"}

These examples was to show you some changes in ruby 2.0. If you want to see more changes go to:
http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/