lib/poly.rb in markdown_exec-2.3.0 vs lib/poly.rb in markdown_exec-2.4.0

- old
+ new

@@ -6,11 +6,13 @@ $pd = false class Poly # attr_reader :table def initialize(table = {}) - @table = table.tap{|ret| pp [__LINE__,'Poly.initialize()','table',table.to_yaml] if $pd } + @table = table.tap { |ret| + pp [__LINE__, 'Poly.initialize()', 'table', table.to_yaml] if $pd + } end def fetch(key, *args) key_sym = key.to_sym if respond_to?("get_#{key}") @@ -18,20 +20,25 @@ elsif @table.key?(key_sym) @table[key_sym] elsif block_given? yield key_sym elsif args.count.positive? -# binding.irb + # binding.irb args.first else -binding.irb + binding.irb raise KeyError, "key not found: #{key}" - end.tap{|ret| pp([__LINE__,"Poly.fetch #{key} #{args}",'->',ret]) if $pd } + end.tap { |ret| + pp([__LINE__, "Poly.fetch #{key} #{args}", '->', + ret]) if $pd + } end def key?(name) - @table.key?(name.to_sym).tap{|ret| pp([__LINE__,"Poly.key? #{name}",'->',ret]) if $pd } + @table.key?(name.to_sym).tap { |ret| + pp([__LINE__, "Poly.key? #{name}", '->', ret]) if $pd + } end def method_missing(name, *args) pt = nil if name.to_s.end_with?('=') @@ -53,50 +60,62 @@ pt = 'send name' @table.send(name, *args) else pt = 'table read' @table[name.to_sym] - end.tap{|ret| pp([__LINE__,"Poly.method_missing #{name} #{args.map(&:to_s).join(' ')}",pt,'->',ret]) if $pd } + end.tap { |ret| + pp([__LINE__, + "Poly.method_missing #{name} #{args.map(&:to_s).join(' ')}", pt, '->', ret]) if $pd + } end def respond_to_missing?(name, include_private = false) # name.to_s.end_with?('=') || @table.key?(name.to_sym) || @table.respond_to?(name) || super - (name.to_s.end_with?('=') || @table.key?(name.to_sym) || @table.respond_to?(name) || super).tap{|ret| pp([__LINE__,"Poly.respond_to_missing? #{name}",'->',ret]) if $pd } + (name.to_s.end_with?('=') || @table.key?(name.to_sym) || @table.respond_to?(name) || super).tap { |ret| + pp([__LINE__, "Poly.respond_to_missing? #{name}", '->', ret]) if $pd + } end def [](key) if respond_to?("get_#{key}") send("get_#{key}") else @table[key.to_sym] - end.tap{|ret| pp([__LINE__,"Poly.[] #{key}",'->',ret]) if $pd } + end.tap { |ret| pp([__LINE__, "Poly.[] #{key}", '->', ret]) if $pd } end def []=(key, value) if respond_to?("set_#{key}") send("set_#{key}", value) else @table[key.to_sym] = value - end.tap{|ret| pp([__LINE__,"Poly.[]= #{key} #{value}",'->',ret]) if $pd } + end.tap { |ret| + pp([__LINE__, "Poly.[]= #{key} #{value}", '->', + ret]) if $pd + } end # for export to Prompt library # def merge(*args) # Proc.new { |x| @table.merge x } # end def merge(*args) -# pp caller -# binding.irb - @table.merge(*args).tap{|ret| pp([__LINE__,"Poly.merge",'->',ret]) if $pd } + # pp caller + # binding.irb + @table.merge(*args).tap { |ret| + pp([__LINE__, "Poly.merge", '->', ret]) if $pd + } end # for export to Prompt library def to_h - @table.tap{|ret| pp([__LINE__,"Poly.to_h",'->',ret]) if $pd } + @table.tap { |ret| pp([__LINE__, "Poly.to_h", '->', ret]) if $pd } end def to_yaml - @table.to_yaml.tap{|ret| pp([__LINE__,"Poly.to_yaml",'->',ret]) if $pd } + @table.to_yaml.tap { |ret| + pp([__LINE__, "Poly.to_yaml", '->', ret]) if $pd + } end end # class CustomStruct < Poly # # Custom setter for virtual attribute :full_name