Class: Structure::Double

Inherits:
BasicObject
Defined in:
lib/structure.rb

Overview

A double that stands in for a yet-to-be-defined class. Otherwise known as “lazy evaluation.”

Idea lifted from: github.com/soveran/ohm/

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Double

Returns a new instance of Double.



41
42
43
# File 'lib/structure.rb', line 41

def initialize(name)
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mth, *args, &block) ⇒ Object (private)



49
50
51
52
53
54
# File 'lib/structure.rb', line 49

def method_missing(mth, *args, &block)
  @unwrapped ? super : @unwrapped = true
  ::Kernel.const_get(@name).send(mth, *args, &block)
ensure
  @unwrapped = false
end

Instance Method Details

#to_sObject



45
46
47
# File 'lib/structure.rb', line 45

def to_s
  @name.to_s
end