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

Enabling password authentication for new ec2 box | ssh, ssh config, EC2 setup, new user in EC2, PasswordAuthentication

What's the difference between "include" and "require" in Ruby?