views:

31

answers:

1

Hi All,

I want to extend Date class in ruby.Actually what I want to do is that add a method to Date class. Following is an example

I want to add 'my_simple_method' method to Date class

def my_simple_method 
 puts 'this is from my_simple_method'
end

after adding this users should be able to call this method as

date_obj = Date.parse('2010-07-01')
puts date_obj.my_simple_method

should print 'this is from my_simple_method'

thanks in advance

cheers

sameera

+3  A: 
class Date
  def my_simple_method
    puts 'this is from my_simple_method'
  end
end
Jörg W Mittag
i'd remove `puts` (we should `return` that)
mykhal
thanks Mittag,sorry i was out for last few days
sameera207