-
Book Overview & Buying
-
Table Of Contents
Polished Ruby Programming - Second Edition
By :
There are two separate approaches to metaprogramming in Ruby. The two approaches each have advantages and disadvantages, and the most appropriate one to use is situation-dependent.
So far in this chapter, you've seen examples using define_method, which is one of the methods used in block-based metaprogramming. There are other block-based metaprogramming methods, such as Class.new, Module.new, and Kernel#define_singleton_method:
Class.new do
# class-level block metaprogramming
end
Module.new do
# module-level block metaprogramming
end
define_singleton_method(:method) do
# singleton-method defining block metaprogramming
end
Let's say you are working on a module named Rusty, for writing rusty code. Rusty code strives to be one-third more efficient than Ruby code, by defining methods using only two characters, fn, instead of the normal three you need in Ruby (def). It also supports defining methods that return static values...
Change the font size
Change margin width
Change background colour