Sha256: c9cdfd0c3186e9242331aa1912b93a27637813723a791132e7c3e7794033796f

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 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
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.4.0 lib/symbol.fy