Skip to content

Instantly share code, notes, and snippets.

@vinhnglx
Created December 27, 2014 08:37
Show Gist options
  • Save vinhnglx/38c00d2506868561cc9f to your computer and use it in GitHub Desktop.
Save vinhnglx/38c00d2506868561cc9f to your computer and use it in GitHub Desktop.
Class method inside class
# 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