Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BlankSlate
- instance_methods.each { |m| undef_method m unless m =~ /^__/ or m =~ /send/ }
- end
- class Remold < BlankSlate
- REMOLD_CACHE = ''
- def method_missing meth, *args, &block
- __remold__handle meth, *args, &block
- end
- def p *args, &block
- __remold__handle :p, *args, &block
- end
- def __remold_handle meth, *args, &block
- Kernel.p [:method_missing, meth, args]
- __build_tag__(meth, *args, &block)
- end
- # build a tag for `name`, using `args` and an optional block that
- # will be yielded
- def __build_tag__(name, args=nil, &block)
- Kernel.p [:build_tag, name, args]
- out = "<#{name}"
- if block_given?
- out << ( args ? args.inject(''){ |s,v| s+%{ #{v[0]}="#{v[1]}"} } : '' )
- out << ">#{yield}</#{name}>"
- else
- out << args.inject(''){ |s,v| s+%{ #{v[0]}="#{v[1]}"} } if args
- out << ' />'
- end
- REMOLD_CACHE << out
- end
- end
- class Template < Remold
- def simple
- p
- end
- end
- template = Template.new
- template.simple
Add Comment
Please, Sign In to add comment