Module: Ryo::Keywords

Included in:
Ryo
Defined in:
lib/ryo/keywords.rb

Overview

The Ryo::Keywords module implements Ryo equivalents to some of JavaScript's keywords - for example: the in and delete operators. The instance methods of this module are available as singleton methods on the Ryo module.

Instance Method Summary collapse

Instance Method Details

#delete(ryo, property)

Note:

This method does not delete properties from the prototype(s) of a Ryo object.
For that - see Ryo::Reflect#delete!.

This method returns an undefined value.

The #delete method deletes a property from a Ryo object. More or less equivalent to JavaScript's "delete" operator.

Parameters:



58
59
60
61
62
63
64
65
66
# File 'lib/ryo/keywords.rb', line 58

def delete(ryo, property)
  property = property.to_s
  if property?(ryo, property)
    table_of(ryo).delete(property)
  else
    return if getter_defined?(ryo, property)
    define_method!(ryo, property) { ryo[property] }
  end
end

#fn(&b) ⇒ Ryo::Function Also known as: function

Returns a Ryo function.

Examples:

point = Ryo(x: 0, y: 0, print: Ryo.fn { print x, y, "\n" })
point.print.()

Parameters:

  • b (Proc)

    The function's body.

Returns:

See Also:



21
22
23
# File 'lib/ryo/keywords.rb', line 21

def fn(&b)
  Ryo::Function.new(&b)
end

#in?(ryo, property) ⇒ Boolean

Equivalent to JavaScript's in operator.

Parameters:

Returns:

  • (Boolean)

    Returns true when property is a member of ryo, or its prototype chain.



37
38
39
40
# File 'lib/ryo/keywords.rb', line 37

def in?(ryo, property)
  return false unless ryo
  property?(ryo, property) || in?(prototype_of(ryo), property)
end