Skip to content

Instantly share code, notes, and snippets.

@meltingice
Last active December 17, 2015 11:09
Show Gist options
  • Save meltingice/5600499 to your computer and use it in GitHub Desktop.
Save meltingice/5600499 to your computer and use it in GitHub Desktop.
var myClass = {
myMethod: function () {
console.log('foo');
}
};
// These are all equivalent in JS
myClass.myMethod()
myClass['myMethod']()
class MyClass
def self.my_method
puts 'foo'
end
# If you want to get fancy
def self.[](m)
self.send(m)
end
end
# These are all equivalent for this class
MyClass.my_method
MyClass.send(:my_method) # Literally sends this message to the class
MyClass[:my_method] # Because we defined the [] method for our class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment