Ruby one of the method of creating a single ton method | Ruby, single ton method

cat = String.new("cat")
def cat.speak
    'miaow'
end
cat.speak #=> "miaow" 
cat.singleton_methods #=> ["speak"] 

Comments

Popular posts from this blog

Rails Memcache issues

Rails working with multiple databases customize the generator | Rails, multiple databases, customize generator

Ruby on Rails 3.x Skip callback and validation and reset Callback | Ruby on Rails, Skip callback, validation, reset Callback