Feature #6243

Make ERB Ruby's Super Power

Added by Thomas Sawyer over 3 years ago. Updated over 3 years ago.

[ruby-core:44046]
Status:Rejected
Priority:Normal
Assignee:-

Description

As a Super Ruby Developer
I want to make Ruby Super Developery
Given wimpy Ruby, coding is arduous:

class Letters
def a
"Aa"
end

def b
  "Bb"
end

# Oh, dear St. V! It's just too long. I don't want to go on!

Then Super Ruby saves the day!

class Letters
<%= ('a'...'z').each do |letter| %>
def <%= letter %>
"<%= letter.upcase %><%= letter %>"
end
<% end %>
end

letters = Letters.new

letters.a #=> "Aa"
letters.b #=> "Bb"

Imagine the power of Ruby ** Ruby! It's like putting Ruby in a phone booth and out pops Ruby with big on chest. And like that, Super Ruby destroys all super villain languages like PHP!

And you can't reject b/c this issue is all Gherkin which makes it legit.

History

#1 Updated by Aaron Patterson over 3 years ago

  • Category changed from core to Joke

#2 Updated by George Koehler over 3 years ago

=begin
The original poster's code (for ERB) fails with SyntaxError.

This code (for plain Ruby) works:
class Letters
('a'..'z').each do |letter|
result = letter.upcase + letter
define_method(letter) { result }
end
end
=end

#3 Updated by Thomas Sawyer over 3 years ago

@kernigh You actually tried it!? Sweet!

Looking it over the error was probably b/c the first <%= should not have the =.

Of course this was for April Fool's Day. As your code shows Ruby is quite capable of meta-programming without ERB based macro system... albeit not quite as "super"! :)

I note, though, it's not quite useless either. I've used similar idea to update VERSION = in version.rb file of some projects before.

#4 Updated by Aaron Patterson over 3 years ago

  • Status changed from Open to Rejected

Closing since April 1st has completed. :-)

Also available in: Atom PDF