Class: R::SymbolRef
- Inherits:
-
Object
- Object
- R::SymbolRef
- Includes:
- BinaryOperators, ExpBinOp, LogicalOperators
- Defined in:
- lib/R_interface/ruby_extensions.rb
Constant Summary collapse
- REF_RUBY_RESERVED =
%i[ to_str to_path to_ary to_int to_f to_r to_proc to_hash to_h to_a call ].freeze
Instance Method Summary collapse
- #+@ ⇒ Object
-
#initialize(name) ⇒ SymbolRef
constructor
A new instance of SymbolRef.
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #to_r_symbol ⇒ Object
- #up_to(other_object) ⇒ Object
- #~@ ⇒ Object
Methods included from LogicalOperators
Methods included from ExpBinOp
#assign, #coerce, #exec_bin_oper, #inter
Methods included from BinaryOperators
#!=, #%, #*, #**, #+, #-, #/, #<, #<=, #>, #>=, #_, #eq, #int_div, #til
Constructor Details
#initialize(name) ⇒ SymbolRef
Returns a new instance of SymbolRef.
48 49 50 |
# File 'lib/R_interface/ruby_extensions.rb', line 48 def initialize(name) @name = name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/R_interface/ruby_extensions.rb', line 73 def method_missing(method_name, *args) super if REF_RUBY_RESERVED.include?(method_name) name = R::Support.convert_symbol2r(method_name) r_args = [self, *args].map { |arg| R::Support.parse_arg(arg) } expr = "#{name}(#{r_args.join(", ")})" res = R::Language.allocate res.instance_variable_set(:@r_interop, expr) res.expression = expr res end |
Instance Method Details
#+@ ⇒ Object
56 57 58 59 60 |
# File 'lib/R_interface/ruby_extensions.rb', line 56 def +@ var_name = R::Support.generate_var_name R.bridge.eval_r("#{var_name} <- as.name('#{to_r_symbol}')") R::Object.build(var_name) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
84 85 86 87 88 |
# File 'lib/R_interface/ruby_extensions.rb', line 84 def respond_to_missing?(method_name, include_private = false) return false if method_name == :r_interop || method_name == :expression return false if REF_RUBY_RESERVED.include?(method_name) true end |
#to_r_symbol ⇒ Object
52 53 54 |
# File 'lib/R_interface/ruby_extensions.rb', line 52 def to_r_symbol @name.to_s.gsub(/__/, ".") end |