class Hash

Public Instance Methods

as_alist() click to toggle source

Creates and returns a new hash tabke with the same keys and values and tags it to be rendered as an association list by the to_lisp method.

For example, “`{:a => :b, :x => 1}“` would be rendered as

“`

((a . b) (x . 1))

“`

# File lib/spectator/emacs.rb, line 80
def as_alist
  merge(:__render_as => :alist)
end
as_flat_list() click to toggle source

Creates and returns a new hash tabke with the same keys and values but tagged to be rendered as a flat list by the to_lisp method.

For example, “`{:a => :b, :x => 1}“` would be rendered as

“`

(a b x 1)

“`

# File lib/spectator/emacs.rb, line 92
def as_flat_list
  merge(:__render_as => :flat )
end
as_plist() click to toggle source

Creates and returns a new hash table with the same keys and values but tagged to be rendered as a property list by the to_lisp method. The keys must be symbols, and they will be rendered as keywords.

For example, “`{:a => :b, :x => 1}“` would be rendered as

“`

(:a b :x 1)

“`

# File lib/spectator/emacs.rb, line 105
def as_plist
  merge(:__render_as => :plist)
end
pjoin(string_list) click to toggle source
# File lib/spectator/emacs.rb, line 119
def pjoin(string_list)
  "(#{string_list.join ' '})"
end
rendering_type() click to toggle source

Returns a symbol indicating how the hash will be rendered by the to_lisp method. The possible values are :flat, :alist, :plist.

# File lib/spectator/emacs.rb, line 111
def rendering_type
  self[:__render_as] or :plist
end
to_lisp() click to toggle source

Renders the hash as a list, depending on how it has been tagged. If the hash has not been tagged, it will be rendered as a property list, see as_plist.

# File lib/spectator/emacs.rb, line 118
def to_lisp
  def pjoin(string_list)
    "(#{string_list.join ' '})"
  end
  h = self.clone
  h.delete(:__render_as)
  case rendering_type
  when :alist
    pjoin(h.map { |k, v| "(#{k.to_lisp} . #{v.to_lisp})" })
  when :flat
    pjoin(h.map { |k, v| "#{k.to_lisp} #{v.to_lisp}" })
  when :plist
    pjoin(h.map { |k, v| "#{k.keyword.to_lisp} #{v.to_lisp}" })
  end
end