Created
December 27, 2014 08:37
-
-
Save vinhnglx/38c00d2506868561cc9f to your computer and use it in GitHub Desktop.
Class method inside class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First | |
class Example | |
def hello | |
puts 'hello' | |
end | |
def vinh | |
puts 'vinh' | |
end | |
end | |
example = Example.new # We need initialize Example class,first. | |
example.hello # call method hello via example's variable --> "hello" | |
# Second | |
class Example | |
def Example.hello | |
puts 'hello' | |
end | |
def Example.vinh | |
puts 'vinh' | |
end | |
end | |
Example.vinh # "vinh" | |
# By the way, the Second can write | |
class Example | |
def self.hello | |
puts 'hello' | |
end | |
def self.vinh | |
puts 'vinh' | |
end | |
end | |
Example.hello # "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment