News for hackers. Stuff that matters.
Re:New Ruby 1.9 Features, Tips & Tricks by carbon8 on Monday February 21, 2011 @03:12PM (#2246946)
Agreed. If there is anyone here who knows the justification for the latter two, please explain.

Edit: found the explanation for the last one: http://www.aimred.com/news/developers/2008/08/14/unlocking_t... So, basically, it's just using it as a normal case equality operator and you generally shouldn't use it in place of a regular #call.

Re:New Ruby 1.9 Features, Tips & Tricks by farrel on Monday February 21, 2011 @03:24PM (#2246997)
Proc#=== allows you to do this:

  def multiple_of( n )
    lambda{ |x| x.modulo( n ).zero? }
  end

  case 10
  when multiple_of( 3 ):
    puts "3!"
  when multiple_of( 4 ):
    puts "4!"
  when multiple_of( 2 ):
    puts "2!"
  end
Basically you can now run code when checking case equality (===).
Re:New Ruby 1.9 Features, Tips & Tricks by petercooper on Monday February 21, 2011 @08:06PM (#2248126)
Since we're talking Ruby 1.9 here, that code won't even run :-( .. drop the colons and you're good though! :-) But if we're really talking Ruby 1.9, you could also go with:

    ->(x){ x % n == 0 }
Re:New Ruby 1.9 Features, Tips & Tricks by rue on Monday February 21, 2011 @05:00PM (#2247415)
Or, more simply:

    case $stdin.gets.chomp
    when lambda {|matchobj| matchobj.count("!") > 1 }
      puts "Quitcher yelling!"
    when "hi"
      puts "Hi yourself"
    end