From: Gregory Brown Date: 2007-05-11T13:11:02+09:00 Subject: Re: Defending Ruby's OOP On 5/10/07, Pe�a, Botp wrote: > From: Jason Roelofs [mailto:jameskilton@gmail.com] : > # Or better yet, tell him to design a language that has "if" > # "unless" etc as objects and see where that goes. What does having > # if/unless as objects even mean? > > Maybe they mean a boolean class. I myself would like a boolean class in ruby. Sometimes, i feel if-else constructs too restrictive,.. maybe i hate grammar rules.. (maybe because i find english weird language??) > > anyway, can we chain booleans like this? > > (x<2).iftrue{"got it!"}.capitalize.each{|c| puts c} to get each char, you don't do each, you do something like each_byte { |c| c.chr } But here's a naive implementation of what you're looking for: class Null def self.method_missing(id,*args) self end end class Object def iftrue self ? yield : Null end end x = 1 (x<2).iftrue{"got it!"}.capitalize.each_byte {|c| puts c.chr} x = 3 (x<2).iftrue{"got it!"}.capitalize.each_byte {|c| puts c.chr }