Module: Bondage

Includes:
Enumerable
Defined in:
lib/bondage.rb

Overview

:include:description.rdoc

SYNOPSIS

:include:synopsis.rb

Constant Summary collapse

VERSION =
'0.1.2'

Instance Method Summary collapse

Instance Method Details

#[]=(name, value) ⇒ Object

Assign the variable within the binding

  • If your implementation supports ObjectSpace, this is relatively safe. This preserves object identity. (Copy by reference.)

  • If not, the right-hand-side gets it’s string value eval’ed



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

def []=(name, value)
  if defined?(ObjectSpace)
    eval("#{sanitize(name)} = ObjectSpace._id2ref(#{value.object_id})")
  else
    eval("#{sanitize(name)} = #{value}")
  end
end

#classvarsObject

Hash of class variables (with ‘@@’)



24
# File 'lib/bondage.rb', line 24

def classvars; list_all :class_variables; end

#constsObject

Hash of constants



26
# File 'lib/bondage.rb', line 26

def consts; list_all :constants; end

#each(&proc) ⇒ Object

Iterator over locals; base for Enumerable methods.



29
30
31
# File 'lib/bondage.rb', line 29

def each(&proc)
  locals.each(&proc)
end

#globalsObject

Hash of global variables (with ‘$’)



20
# File 'lib/bondage.rb', line 20

def globals; list_all :global_variables; end

#instvarsObject

Hash of instance variables (with ‘@’)



22
# File 'lib/bondage.rb', line 22

def instvars; list_all :instance_variables; end

#localsObject

Hash of local variables



18
# File 'lib/bondage.rb', line 18

def locals; list_all :local_variables; end

#lookup(name) ⇒ Object Also known as: []

Return the value of the symbol in the binding.



35
36
37
38
39
40
41
# File 'lib/bondage.rb', line 35

def lookup(name)
  begin
    eval(sanitize(name));
  rescue NameError
    return nil
  end
end

#to_sObject

Adds “+Bondage” to default string



12
13
14
15
# File 'lib/bondage.rb', line 12

def to_s
  c = self.class.to_s
  super.sub(c, c + "+Bondage")
end