Class: R::Receiver

Inherits:
ERObj
  • Object
show all
Defined in:
lib/R.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, x) ⇒ Receiver

Returns a new instance of Receiver.



52
53
54
55
56
# File 'lib/R.rb', line 52

def initialize (klass, x)
  @classname  = klass
  @attributes = R(%{ attributes(obj) },:obj=>x)
  super(x)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/R.rb', line 102

def method_missing (sym, *args)
  if args.empty?
    return self[sym]
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



58
59
60
# File 'lib/R.rb', line 58

def attributes
  @attributes
end

#robjObject (readonly)

Returns the value of attribute robj.



58
59
60
# File 'lib/R.rb', line 58

def robj
  @robj
end

Instance Method Details

#[](sym = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/R.rb', line 60

def [] (sym = nil)
  if sym
    name = sym.to_s
    name = name.gsub(/_/, '.')
    begin
      ret = @r['$'].call(@robj, name)
    rescue RException
      ret = @attributes[name]
    end
    return __converter__(ret)
  else
    return __converter__(to_ruby)
  end
end

#__converter__(arg) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/R.rb', line 75

def __converter__ (arg)
  case arg
  when Array
    return arg.to_ca.map!{|v| __converter__(v) }
  when Hash
    new_hash = {}
    arg.each do |k,v|
      new_hash[k] = __converter__(v)
    end
    return new_hash
  when RObj
    return R::CONVERTER[arg]
  else
    return arg
  end
end

#inspectObject



96
97
98
99
100
# File 'lib/R.rb', line 96

def inspect
  return "<R:Receiver: class=#{@classname} \n" \
         "             attributes=#{@attributes.inspect} \n" \
         "             data=#{to_ruby} >"
end

#methodObject



92
93
94
# File 'lib/R.rb', line 92

def method
  return self[:method]
end

#to_aryObject



110
111
112
# File 'lib/R.rb', line 110

def to_ary
  return [self.to_s]
end