Skip to content

Instantly share code, notes, and snippets.

@robertodecurnex
Last active August 29, 2015 14:19
Show Gist options
  • Save robertodecurnex/3caeec3f2528558ae6de to your computer and use it in GitHub Desktop.
Save robertodecurnex/3caeec3f2528558ae6de to your computer and use it in GitHub Desktop.
where the wild ruby-things are
# upper-camel case
class ClassLikeName
end
# lower-snake case
def method_like_name
return 'method return value'
end
ClassLikeName #=> ClassLikeName
# returns the class itself
method_like_name #=> "method return value"
# executes the method and returns its return value
ClassLikeName.new() #=> #<ClassLikeName:0x007f92607d8d50>
# returns a new instance of the class
method_like_name() #=> "method return value"
# same as before. executes the method and returns its return value.
ClassLikeMethod() #=> NoMethodError: undefined method `Ho' for main:Object
# The `()` that follows the class forces ruby to call a method with that name.
method_like_name.new() #=> NoMethodError: undefined method `new' for "method return value":String
# #new gets chained to the return value of the method.
# upper-camel case
class ClassLikeName
end
# upper-camel case
def ClassLikeName
return 'method return value'
end
# lower-snake case
def method_like_name
return 'method return value'
end
Object.constants #=> [..., ClassLikeName,...]
self.private_methods #=> [..., ClassLikeName, method_like_name,...]
# upper-camel case
class ClassLikeName
end
# upper-camel case
def ClassLikeName
return 'method return value'
end
# First note that this works just fine.
ClassLikeName #=> ClassLikeName
# return the class (it wins over the method).
ClassLikeName.new() #=> #<ClassLikeName:0x007f92607d8d50>
# returns a new instance of the class. class 2 - method 0 (such a looser :P)
ClassLikeName() #=> "method return value"
# executes the method and returns its return value. See, the `()` forces ruby to take the "method" path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment