Skip to content

Instantly share code, notes, and snippets.

@davidpaniz
Created December 22, 2014 21:16
Show Gist options
  • Save davidpaniz/8efd4310621b199ddbbd to your computer and use it in GitHub Desktop.
Save davidpaniz/8efd4310621b199ddbbd to your computer and use it in GitHub Desktop.
class Picapau
def voa
p 'estou voando'
end
end
woody = Picapau.new
amigo = Picapau.new
woody.voa # => estou voando
amigo.voa # => estou voando
def woody.rir
"hehehehe-hehehehe-hehehehehehe"
end
p woody.rir # => hehehehe-hehehehe-hehehehehehe
# p amigo.rir # => NoMethodError: undefined method ‘rir’ for ...
p woody.class # => Picapau
p amigo.class # => Picapau
p woody.class == amigo.class # => true
p woody.methods - amigo.methods # => ["rir"]
p woody.singleton_methods # => ["rir"]
p amigo.singleton_methods # => []
class Object
def singleton_class
class << self
self
end
end
end
p woody.singleton_class # => Class:Picapau:0x...
p amigo.singleton_class # => Class:Picapau:0x...(diferente)
p woody.singleton_class == amigo.singleton_class # => false
class ARBase
def self.belongs_to
def leo
p 'leo'
end
end
end
class B < ARBase
belongs_to
end
B.new.leo # => leo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment