Reputation: 15294
I tried to make a method (or notation?) like %w, but ruby is not happy with the name of method and give errors all the time. I tried to search a bit, but did not find anything exciting.
Any ideas how to do it?
For example,
def %f(&block)
puts "foo"
end
Upvotes: 2
Views: 224
Reputation: 81530
You'd have to edit Ruby itself in order to do that, at least for YARV Ruby, the C-based implementation of Ruby 1.9 .
parse.y famtour slides 63 to 76 gives an example of someone editing Ruby itself to create another percent method. Not very practical for work situations!
Upvotes: 2
Reputation: 369468
Those aren't methods, those are literal syntax. There are very few languages that do allow creating new literals, but Ruby isn't one of them. Like most languages, the syntax is fixed.
Upvotes: 3
Reputation: 230366
You can't do that. These shortcuts are part of the language.
Upvotes: 4