sameera207
sameera207

Reputation: 16619

Extending Date class in ruby

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

Upvotes: 3

Views: 988

Answers (1)

Jörg W Mittag
Jörg W Mittag

Reputation: 369428

class Date
  def my_simple_method
    puts 'this is from my_simple_method'
  end
end

Upvotes: 4

Related Questions