class TokyoMetro::Document::MakeExamples::Static::EachFile::EachMethod
Public Class Methods
new( indent , title , h , value_in_block , displayed )
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 3 def initialize ( indent , title , h , value_in_block , displayed ) @indent = indent @title = title @hash_const = h.gsub( /\Ahash \: / , "" ) @value_in_block = value_in_block.gsub( /\Avalue in block \: / , "" ) @displayed = displayed.gsub( /\Adisplayed \: / , "" ) end
Public Instance Methods
to_s()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 11 def to_s puts "" puts @title # puts "" # puts code_for_making_example [ top , results ].join( "\n" ) end
Private Instance Methods
actual_code_for_making_example()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 44 def actual_code_for_making_example str = <<-CODE #{@hash_const}.values.map { | #{@value_in_block} | " " * @indent + "\# " + #{evaluated_string} } CODE return str end
code_for_making_example()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 35 def code_for_making_example "#{@hash_const}.values.map { | #{@value_in_block} | #{@displayed} }" end
code_to_output()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 31 def code_to_output "#{@hash_const}.each_value { | #{@value_in_block} | puts #{@displayed} }" end
evaluated_string()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 54 def evaluated_string @displayed.split( / \+ / ).map { | str | code = <<-CODE Proc.new { | #{@value_in_block} | if #{str} == nil "\(nil\)" elsif #{str} == "" "(空文字列)" # elsif #{str}.instance_of?( ::String ) # "\\\"" + #{str} + "\\\"" else #{str}.to_s end }.call( #{@value_in_block} ) CODE code.gsub( /\n *\Z/ , "" ) }.join( " + " ) end
results()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 39 def results # puts actual_code_for_making_example return eval( actual_code_for_making_example ) end
top()
click to toggle source
# File lib/tokyo_metro/document/make_examples/static/each_file/each_method.rb, line 22 def top ary = ::Array.new ary << @title [ "\# \@example" , "\# #{code_to_output}" , "\# \=\>" ].each do | row | ary << ( " " * @indent + row ) end ary.join( "\n" ) end