Class: Otaku::Handler::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/otaku/handler/context.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(methods_hash) ⇒ Context

Returns a new instance of Context.



7
8
9
10
11
12
# File 'lib/otaku/handler/context.rb', line 7

def initialize(methods_hash)
  @code = 'Class.new{ %s }.new' %
    methods_hash.map do |method, val|
      'def %s; %s; end' % [method, method_body(val)]
    end.sort.join('; ')
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/otaku/handler/context.rb', line 5

def code
  @code
end

Instance Method Details

#eval!Object



14
15
16
# File 'lib/otaku/handler/context.rb', line 14

def eval!
  eval(@code, nil, '(generated class)', 1)
end

#marshal_dumpObject



18
19
20
# File 'lib/otaku/handler/context.rb', line 18

def marshal_dump
  [@code]
end

#marshal_load(data) ⇒ Object



22
23
24
# File 'lib/otaku/handler/context.rb', line 22

def marshal_load(data)
  @code, _ = data
end