Last active
December 17, 2015 11:09
-
-
Save meltingice/5600499 to your computer and use it in GitHub Desktop.
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
var myClass = { | |
myMethod: function () { | |
console.log('foo'); | |
} | |
}; | |
// These are all equivalent in JS | |
myClass.myMethod() | |
myClass['myMethod']() |
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
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