Class: JS::Object

Inherits:
BasicObject
Defined in:
lib/p5rb_cli/static/p5editor.rb

Overview


Library


JS::Object can call property via function style

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/p5rb_cli/static/p5editor.rb', line 219

def method_missing(sym, *args, &block)
  ret = self[sym]

  case ret.typeof
  when "undefined"
    str = sym.to_s
    if str[-1] == "="
      self[str.chop.to_sym] = args.first
      return args.first
    end

    super
  when "function"
    self.call(sym, *args, &block).to_r
  else
    ret.to_r
  end
end

Instance Method Details

#respond_to_missing?(sym, include_private) ⇒ Boolean

Returns:

  • (Boolean)


238
239
240
241
# File 'lib/p5rb_cli/static/p5editor.rb', line 238

def respond_to_missing?(sym, include_private)
  return true if super
  self[sym].typeof != "undefined"
end

#to_rObject



243
244
245
246
247
248
249
250
251
252
# File 'lib/p5rb_cli/static/p5editor.rb', line 243

def to_r
  case self.typeof
  when "number"
    self.to_f
  when "string"
    self.to_s
  else
    self
  end
end