class Object
Constants
- Address
- KeyHash
- Money
- Nat
Public Class Methods
const_missing( name )
click to toggle source
Calls superclass method
# File lib/michelson/michelson.rb, line 141 def Object.const_missing( name ) puts "const_missing:" pp name if name.to_s.start_with?( "Map‹" ) Map elsif name.to_s.start_with?( "BigMap‹" ) BigMap else super end end
Public Instance Methods
Option( arg )
click to toggle source
# File lib/michelson/michelson.rb, line 71 def Option( arg ) arg; end
define_function( method, signature )
click to toggle source
# File lib/michelson/michelson.rb, line 22 def define_function( method, signature ) ## todo/fix: check if we are in a module ? ## only use Object.__send__ as a (last) fallback (for convenience) - why? why not? Object.__send__( :alias_method, "#{method}_unsafe", method ) puts "define function #{method}:" pp signature define_method method do |*args| if args.size == 0 call_inspect = "#{method}()" else args_inspect = args.map { |arg| arg.inspect }.join( ", " ) call_inspect = "#{method}( #{args_inspect} )" end puts "calling #{call_inspect}..." __send__( "#{method}_unsafe", *args ).tap do |result| puts "returning:" pp result end end end
entry( *args )
click to toggle source
# File lib/michelson/michelson.rb, line 57 def entry( *args ) sig( *args ) end
failwith( msg, *args )
click to toggle source
# File lib/michelson/michelson.rb, line 76 def failwith( msg, *args ) if args.size == 0 msg_inspect = msg else args_inspect = args.map { |arg| arg.inspect }.join( ", " ) msg_inspect = "#{msg}: #{args_inspect}" end fail msg_inspect end
init( *args )
click to toggle source
# File lib/michelson/michelson.rb, line 53 def init( *args ) sig( *args ) end
is_nat( num )
click to toggle source
# File lib/michelson/michelson.rb, line 109 def is_nat( num ) if num >=0 num ## a.k.a Some else nil ## a.k.a None end end
match( obj, matchers )
click to toggle source
# File lib/michelson/michelson.rb, line 154 def match( obj, matchers ) ## pp obj ## pp matchers ## note: assume None/Some for now if obj matchers[:Some].call( obj ) else ## none matchers[:None].call end end
sig( *args )
click to toggle source
# File lib/michelson/michelson.rb, line 47 def sig( *args ) method = args.pop # remove last element (assume it's a method) signature = args define_function( method, signature ) end
type( class_name, *args )
click to toggle source
# File lib/michelson/michelson.rb, line 5 def type( class_name, *args ) puts "define type #{class_name}:" pp args if args.size == 1 && (args[0].is_a?( Class ) || args[0].is_a?( Module )) klass = args[0] Kernel.const_set( class_name, klass ) elsif args.size == 1 && args[0].is_a?( Hash ) keys = args[0].keys klass = Struct.new( *keys ) Kernel.const_set( class_name, klass ) else raise ArgumentError.new( "Class|Module or Hash expected") end end