-
-
Save karthiks/1858132 to your computer and use it in GitHub Desktop.
Five lines that turn Ruby into a different language
This file contains 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 Object | |
def method_missing m, *args | |
Object.respond_to?(m, true) ? Object.send(m, self, *args) : super | |
end | |
end |
@michaelfeathers tweeted the gist as "Five lines that turn Ruby into a different language". I guess, by language he meant DSL.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question by @solojavier: What is this about? Newbie in ruby. (I had the same question, in my mind! - A Ruby Enthusiast)
Explanation given by @michaelfeathers: It allows you to chain functions onto arbitrary objects. Each function that you use in this style is understood to accept the return value of the previous link in the chain as its first argument. I know that is abstract, but here is a code example:
ArrayMac: A language is a set of conventions around expression. The term DSL (Domain-Specific Language) uses the word 'language' in this sense.