From: Charles Steinman Date: 2005-07-04T02:15:44+09:00 Subject: Re: two questions: one for XML Builder, one for ERB. Greg Chen(China) wrote: > 1. > require_gem 'builder' > > > builder = Builder::XmlMarkup.new(:target�=>STDOUT, :indent=>2) > builder.person { |b| b.name("Jim"); b.phone("555-1234") } > > > # > # Prints: > # > # Jim > # 555-1234 > # > > > The code is clear, but how to understand "builder.person"? A dynamic > method? Yep. Builder uses method_missing to dynamically create markup methods as they are called. > 2. > > > require 'erb' > File.open( ARGV[0] ) { |fh| > erb = ERB.new( fh.read ) > print erb.result( binding ) > > > > } > > > How to understand "binding"? Where does it defined? It's defined in the Kernel module. From "ri Kernel.binding": --------------------------------------------------------- Kernel#binding binding -> a_binding ------------------------------------------------------------------------ Returns a +Binding+ object, describing the variable and method bindings at the point of call. This object can be used when calling +eval+ to execute the evaluated command in this environment. Also see the description of class +Binding+. def getBinding(param) return binding end b = getBinding("hello") eval("param", b) #=> "hello"