Skip to content

Instantly share code, notes, and snippets.

@brainopia
Created February 15, 2012 21:19
Show Gist options
  • Save brainopia/1839064 to your computer and use it in GitHub Desktop.
Save brainopia/1839064 to your computer and use it in GitHub Desktop.
# call methods like constants
module Foo
def self.bar
'tadam'
end
end
Foo::bar # => tadam
# methods can be capitalized
module Foo
def self.Bar(default='boo')
default
end
end
Foo.Bar # => "boo"
Foo::Bar() # => "boo" - parenthesis are necessary to distinguish from constant
Foo::Bar 'yo' # => "yo"
# previously it was very popular to have a method with the same name as a class to create a new instance of the class
Nokogiri # => Nokogiri
Nokogiri 'xml' # => #<Nokogiri::XML::Document:0x3feb951e84c4 name="document">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment