Parent

Files

Hash

Core Extensions

Public Instance Methods

rekey(*args, &block) click to toggle source

Non-inplace rekey! method.

# File lib/hashery/stash.rb, line 176
def rekey(*args, &block)
  dup.rekey!(*args, &block)
end
rekey!(*args, &block) click to toggle source

Synonym for Hash#rekey, but modifies the receiver in place (and returns it).

foo = { :name=>'Gavin', :wife=>:Lisa }
foo.rekey!{ |k| k.to_s }  #=>  { "name"=>"Gavin", "wife"=>:Lisa }
foo.inspect               #=>  { "name"=>"Gavin", "wife"=>:Lisa }

This method comes from Ruby Facets.

# File lib/hashery/stash.rb, line 158
def rekey!(*args, &block)
  # for backward comptability (TODO: DEPRECATE).
  block = args.pop.to_sym.to_proc if args.size == 1
  if args.empty?
    block = lambda{|k| k.to_sym} unless block
    keys.each do |k|
      nk = block[k]
      self[nk]=delete(k) if nk
    end
  else
    raise ArgumentError, "3 for 2" if block
    to, from = *args
    self[to] = self.delete(from) if self.has_key?(from)
  end
  self
end
to_basicstruct() click to toggle source

Convert a Hash into a BasicStruct.

# File lib/hashery/basicstruct.rb, line 246
def to_basicstruct
  BasicStruct[self]
end
to_stash() click to toggle source

Convert a Hash to a Stash object.

# File lib/hashery/stash.rb, line 146
def to_stash
  Stash[self]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.