Class: Yaml::Sort::Alias

Inherits:
Value
  • Object
show all
Defined in:
lib/yaml/sort/alias.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#comments, #sort

Constructor Details

#initialize(anchors, name) ⇒ Alias

Returns a new instance of Alias.



8
9
10
11
12
# File 'lib/yaml/sort/alias.rb', line 8

def initialize(anchors, name)
  super()
  @anchors = anchors
  @name = name[:value]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/yaml/sort/alias.rb', line 6

def name
  @name
end

Instance Method Details

#<=>(_other) ⇒ Object



34
35
36
# File 'lib/yaml/sort/alias.rb', line 34

def <=>(_other)
  0
end

#delete_valueObject



18
19
20
# File 'lib/yaml/sort/alias.rb', line 18

def delete_value
  @anchors.delete(@name)
end

#to_sObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yaml/sort/alias.rb', line 22

def to_s(*)
  if (s = @anchors.delete(@name))
    separator = case s
                when List, Dictionary then "\n"
                else " "
                end
    "&#{name}#{separator}#{s}"
  else
    "*#{name}"
  end
end

#value?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/yaml/sort/alias.rb', line 14

def value?
  @anchors[@name]
end