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



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/story_teller/experimental/handler_dsl.rb', line 115

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



135
136
137
# File 'lib/story_teller/experimental/handler_dsl.rb', line 135

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

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

Returns:

  • (Boolean)


131
132
133
# File 'lib/story_teller/experimental/handler_dsl.rb', line 131

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