Sha256: 60069959afe79769a7e579e9d829f0ed7e6d9b1d94ed479cd7d81312f3266364

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

class Symbol {
  """
  Symbols are unique identifiers and only created once.

  If there are several occurrances of the same Symbol literal within
  Fancy code, they all refer to the same Symbol object.
  """

  def call: arg {
    """
    This allows Symbols to be used like Blocks
    (e.g. in all methods of Enumerable).
    Example:
          [1, 2, 3] map: 'squared # => [1, 4, 9]
    """

    if: (arg is_a?: Array) then: {
      arg first receive_message: self with_params: $ arg rest
    } else: {
      arg receive_message: self
    }
  }

  def call {
    """
    Sends @self as message to the sender in its context.
    Example:
          'foo call
           # => same as
           self foo

           if: x then: 'foo else: 'bar
           # same as:
           if: x then: { self foo } else: { self bar }
    """

    binding = Binding setup(Rubinius VariableScope of_sender(),
                            Rubinius CompiledMethod of_sender(),
                            Rubinius StaticScope of_sender())
    recv = binding self()
    recv receive_message: self
  }

  def arity {
    1
  }

  def to_sym {
    self
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fancy-0.7.0 lib/symbol.fy
fancy-0.6.0 lib/symbol.fy