May 2010

Chained Comparisons

I think I could need some help to refactor this code…

## Implementing chained comparisons in Ruby

(1..10).each do |x|
  case
  when x < 3
    puts "#{x} is quite low"
  when 3 <= x < 6
    puts "#{x} is quite all right"
  when 6 <= x < 10
    puts "#{x} is quite fine"
  when 10 <= x
    puts "#{x} is quite high"
  end
end


lets
  BEGIN {
        
Object.send(*                                                           
  "ZGVmaW5lX21ldGhvZA=bWV0aG9kX21pc3Npbmc=".unpack("mm"                      )
                                                                          ){|*|}
[[],[61]].inject([]){|_,__|_<<[60,*__]<<[62,*__]}.map{|_|_.pack("c*"        )}.
each { |a| [Float, Fixnum, Comparable].each { |b| b.class_eval               {
c = instance_method(a) and define_method(a) { |d| c.bind(self).call(d) and d }
                                                                      
there                                                                        }
  is                                                                         }
    no              ;FalseClass.class_eval "def %s(*) false end"%a           }
      END                                                                   {}
                                                                            
to                                                                          
  this                                                                      
    madness                                                                  }
                                                                            
this
  is
    RUBY!
      (not perl?)

View Comments

April 2010

Use the Gemspec

February 2010

Introducing SexpBuilder

December 2009

Temple

July 2009

Parkaby

June 2009

Copy'n'Paste

May 2009

GitHub.js

March 2009

Nokogirl

February 2009

Change

January 2009

Tailin' Ruby

December 2008

Copy Folders to a Branch

October 2008

Morse.rb

September 2008

It's a Gash, Gash, Gash

August 2008

Tribute

August 2008

SuperIO

June 2008

Ruby Fishy Edition

April 2008

Moving to Nginx

April 2008

Thank You!

March 2008

RE: Haiku.rb

March 2008

Haiku.rb

February 2008

A Better to_hash

February 2008

A Trip into Random

February 2008

Introducing Gemify