Class: Renjin::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/JRubyR/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rbsexp) ⇒ Attributes





38
39
40
# File 'lib/JRubyR/attributes.rb', line 38

def initialize(rbsexp)
  @rbsexp = rbsexp
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object





46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/JRubyR/attributes.rb', line 46

def method_missing(symbol, *args)
  
  name = symbol.id2name
  name.sub!(/__/,".")
  # Method 'rclass' is a substitute for R method 'class'.  Needed, as 'class' is also
  # a Ruby method on an object
  name.gsub!("rclass", "class")
  
  if name =~ /(.*)=$/
    super if args.length != 1
    args = R.parse(*args)
    ret = R.eval("attr(#{@rbsexp.r}, \"#{name.delete!('=')}\") = #{args}")
  else
    if (args.length == 0)
      # p "retrieving attribute: #{name}"
      ret = R.eval("attr(#{@rbsexp.r}, \"#{name}\")")
      ret.scope = ["attr", @rbsexp, name]
    else
      raise "An attribute cannot have parameters"
    end
  end

  ret
  
end

Instance Attribute Details

#rbsexpObject (readonly)

Returns the value of attribute rbsexp.



32
33
34
# File 'lib/JRubyR/attributes.rb', line 32

def rbsexp
  @rbsexp
end