Module: Pione::Util::VariableHoldable

Defined in:
lib/pione/util/variable-holdable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(subclass) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pione/util/variable-holdable.rb', line 5

def included(subclass)
  class << subclass
    attr_reader :variable_holders

    def hold_variable(name)
      (@variable_holders ||= []) << name
    end

    def hold_variables(*names)
      names.each {|name| hold_variable(name)}
    end

    attr_reader :variable_included

    def include_variable(b)
      @variable_included = b
    end
  end
end

Instance Method Details

#include_variable?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
# File 'lib/pione/util/variable-holdable.rb', line 26

def include_variable?
  unless self.class.variable_included.nil?
    return self.class.variable_included
  else
    self.class.variable_holders.any? do |var|
      val = instance_variable_get("@%s" % var)
      val == self or val.nil? ? false : val.include_variable?
    end
  end
end