How to change verbose code in Ruby to simpler using Metaprogramming?
Posted
by Jian Lin
on Stack Overflow
See other posts from Stack Overflow
or by Jian Lin
Published on 2010-06-06T06:16:55Z
Indexed on
2010/06/06
6:22 UTC
Read the original article
Hit count: 202
ruby
|metaprogramming
It is said that Ruby is a metaprogramming language. I wonder if the first 3 lines can be made less verbose using metaprogramming?
RUBY_VERSION ||= "unknown version"
RUBY_PATCHLEVEL ||= "unknown patchlevel"
RUBY_PLATFORM ||= "unknown platform"
print "Ruby ", RUBY_VERSION, " patch ", RUBY_PATCHLEVEL, " on ", RUBY_PLATFORM
© Stack Overflow or respective owner