Hidden features of Ruby -


continuing "hidden features of ..." meme, let's share lesser-known useful features of ruby programming language.

try limit discussion core ruby, without ruby on rails stuff.

see also:

(please, one hidden feature per answer.)

thank you

from ruby 1.9 proc#=== alias proc#call, means proc objects can used in case statements so:

def multiple_of(factor)   proc.new{|product| product.modulo(factor).zero?} end  case number   when multiple_of(3)     puts "multiple of 3"   when multiple_of(7)     puts "multiple of 7" end 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -