### Home Classes Methods

### In Files

- lib/facets/uri.rb
- lib/facets/ostruct.rb
- lib/facets/random.rb
- lib/facets/shellwords.rb

### Parent

Object

### Methods

- #shelljoin
- #shellwords
- #to_ostruct
- #to_ostruct_recurse

### Included Modules

- Random::HashExtensions

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Random
- Random::ArrayExtensions
- Random::HashExtensions
- Random::IntegerExtensions
- Random::NumericExtensions
- Random::RangeExtensions
- Random::StringExtensions
- Random::StringExtensions::Self
- FileUtils
- FileUtils::DryRun
- FileUtils::NoWrite
- FileUtils::Verbose
- Digest
- Digest::Class
- Digest::Instance
- Multiton
- Multiton::Inclusive
- Multiton::MetaMethods
- URI
- URI::Hash
- URI::Kernel
- Argvector
- Argvector
- ERB
- ERB::OpenTemplate
- Enumerable
- Enumerable::Arguments
- GetoptLong
- GetoptLong::DSL
- Memoizable
- Memoizable::Copy
- Numeric
- Numeric::Multipliers
- Object
- Object::ArgVector
- Timer
- Timer::Dummy
- Array
- BasicObject
- CGI
- Cloneable
- Continuation
- Date
- DateTime
- Equitable
- File
- Find
- Hash
- Instantiable
- Integer
- Interval
- Kernel
- Math
- Module
- Net
- NilClass
- NullClass
- OpEsc
- OpenStruct
- Pathname
- Platform
- Range
- RbConfig
- Set
- Shellwords
- String
- StringScanner
- Time
- Tuple
- YAML
- Zlib

No matching classes.

# Hash

### Public Instance Methods

shelljoin() click to toggle source

    # File lib/facets/shellwords.rb, line 107
    def shelljoin
      shellwords.shelljoin
    end

shellwords() click to toggle source

    # File lib/facets/shellwords.rb, line 87
    def shellwords
      argv = []
      each do |f,v|
        m = f.to_s.size == 1 ? '-' : '--'
        case v
        when false, nil
        when Array
          v.each do |e|
            argv << %[#{m}#{f}="#{e}"]
          end
        when true
          argv << %[#{m}#{f}]
        else
          argv << %[#{m}#{f}="#{v}"]
        end
      end
      argv
    end

to_ostruct() click to toggle source

Turns a hash into a generic object using an OpenStruct.

    o = {'a' => 1}.to_ostruct
    o.a  #=> 1

    # File lib/facets/ostruct.rb, line 172
    def to_ostruct
      OpenStruct.new(self)
    end

to_ostruct_recurse(exclude={}) click to toggle source

Like to_ostruct but recusively objectifies all hash elements as well.

    o = {'a' => { 'b' => 1 }}.to_ostruct_recurse
    o.a.b  #=> 1

The `exclude` parameter is used internally to prevent infinite recursion and is not intended to be utilized by the end-user. But for more advance use, if there is a particular subhash you would like to prevent from being converted to an OpoenStruct then include it in the `exclude` hash referencing itself. Eg.

    h = { 'a' => { 'b' => 1 } }
    o = h.to_ostruct_recurse( { h['a'] => h['a'] } )
    o.a['b']  #=> 1

CREDIT: Alison Rowland, Jamie Macey, Mat Schaffer

    # File lib/facets/ostruct.rb, line 192
    def to_ostruct_recurse(exclude={})
      return exclude[self] if exclude.key?( self )
      o = exclude[self] = OpenStruct.new
      h = self.dup
      each_pair do |k,v|
        h[k] = v.to_ostruct_recurse( exclude ) if v.respond_to?(:to_ostruct_recurse)
      end
      o.__update__(h)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.