Module: Inform::BuilderInstanceMethods

Defined in:
lib/story_teller/experimental/handler_dsl.rb

Overview

The BuilderInstanceMethods module

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/story_teller/experimental/handler_dsl.rb', line 130

def method_missing(method_name, *args, &block)
  # 1) Try the real receiver first (even when a block is present)
  log.debug "@target: #{@target.inspect}"
  return @target.public_send(method_name, *args) if block.nil?
  return @target.public_send(method_name, *args, &block) if @target.respond_to?(method_name)

  # 2) Unknown method + block => define DSL method on behavior
  return super if block.nil?

  local_context = @context
  @behavior.send(:define_method, method_name) do |*call_args, &_block|
    instance_exec(local_context, *call_args, &block)
  end
  method_name
end

Instance Method Details

#define_singleton_method(*args, &blk) ⇒ Object



150
151
152
# File 'lib/story_teller/experimental/handler_dsl.rb', line 150

def define_singleton_method(*args, &blk)
  @target.define_singleton_method(*args, &blk)
end

#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/story_teller/experimental/handler_dsl.rb', line 146

def respond_to_missing?(_method_name, _include_private = false)
  true
end