Class: Hexp::List

Inherits:
Array
  • Object
show all
Defined in:
lib/hexp/list.rb

Overview

A list of nodes

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (List) initialize(nodes)

Create new Hexp::List

Examples:

Hexp::List.new([H[:p], H[:div]])

Parameters:

  • nodes (#to_ary)

    List of nodes



15
16
17
# File 'lib/hexp/list.rb', line 15

def initialize(nodes)
  super nodes.to_ary.freeze
end

Class Method Details

+ (Hexp::List) [](*args)

Convenience constructor

Examples:

Hexp::List[
  Hexp::Node[:marquee, "Try Hexp for instanst satisfaction!"],
  Hexp::Node[:hr],
]

Parameters:

  • args (Array)

    individual nodes

Returns:



32
33
34
# File 'lib/hexp/list.rb', line 32

def self.[](*args)
  new(args)
end

Instance Method Details

- (Boolean) eql?(other)

Value and type equality

Hexp::List is mostly interchangeable with a plain Array, and so equality with `==` delegates to the underlying array, making `Hexp::List[] == []` true.

If you want a stronger comparison, than this version will compare both the value (in this case : contents), and the type.

Examples:

H[:div, [[:span]]].children == [H[:span]]             #=> true
H[:div, [[:span]]].children.eql? [H[:span]]           #=> false
H[:div, [[:span]]].children.eql? Hexp::List[H[:span]] #=> true

Parameters:

  • other (Object)

    Object to compare with

Returns:

  • (Boolean)


79
80
81
# File 'lib/hexp/list.rb', line 79

def eql?(other)
  self == other && self.class == other.class
end

- (Object) inspect

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

String representation

This delegates to the underlying array, so it's not obvious from the output that this is a wrapping class. This is convenient when inspecting nested hexps, but probably something we want to solve differently.

Returns:

  • string



45
46
47
# File 'lib/hexp/list.rb', line 45

def inspect
  __getobj__.inspect
end

- (Array<Hexp::Node>) to_ary

Internal coercion to Array

Examples:

Hexp::List[ H[:p], H[:span] ].to_ary #=> [H[:p], H[:span]]

Returns:



57
58
59
# File 'lib/hexp/list.rb', line 57

def to_ary
  __getobj__
end