Class: Hash

### Home Classes Methods

### In Files

- lib/logging/utils.rb

### Parent

Object

### Methods

- #getopt

### Files

- History.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Logging
- Logging::Appender
- Logging::Appenders
- Logging::Appenders::Buffering
- Logging::Appenders::Email
- Logging::Appenders::File
- Logging::Appenders::Growl
- Logging::Appenders::IO
- Logging::Appenders::RollingFile
- Logging::Appenders::Stderr
- Logging::Appenders::Stdout
- Logging::Appenders::StringIo
- Logging::Appenders::Syslog
- Logging::ColorScheme
- Logging::Config
- Logging::Config::Configurator
- Logging::Config::Configurator::DSL
- Logging::Config::Configurator::Error
- Logging::Config::Configurator::TopLevelDSL
- Logging::Config::YamlConfigurator
- Logging::Config::YamlConfigurator::Error
- Logging::Layout
- Logging::Layouts
- Logging::Layouts::Basic
- Logging::Layouts::Parseable
- Logging::Layouts::Pattern
- Logging::Logger
- Logging::MappedDiagnosticContext
- Logging::NestedDiagnosticContext
- Logging::Proxy
- Logging::RailsCompat
- Logging::Repository
- Logging::Repository::Singleton
- Logging::RootLogger
- Logging::Stats
- Logging::Stats::Sampler
- Logging::Stats::Tracker
- RSpec
- RSpec::Core
- RSpec::Core::Configuration
- RSpec::LoggingHelper
- RSpec::LoggingHelper
- Spec
- Spec::Runner
- Spec::Runner::Configuration
- Object
- Object::LoggingHelper
- File
- FileUtils
- Hash
- Kernel
- Module
- ReentrantMutex
- String

No matching classes.

# Hash

### Public Instance Methods

getopt( key, default = nil, :as => class ) click to toggle source

Returns the value associated with the key. If the has does not contain the key, then the default value is returned.

Optionally, the value can be converted into to an instance of the given class. The supported classes are:

    Integer
    Float
    Array
    String
    Symbol

If the value is `nil`, then no conversion will be performed.

    # File lib/logging/utils.rb, line 25
    def getopt( *args )
      opts = args.last.instance_of?(Hash) ? args.pop : {}
      key, default = args

      val = if has_key?(key);                self[key]
            elsif has_key?(key.to_s);        self[key.to_s]
            elsif has_key?(key.to_s.intern); self[key.to_s.intern]
            else default end

      return if val.nil?
      return val unless opts.has_key?(:as)

      case opts[:as].name.intern
      when :Integer; Integer(val)
      when :Float;   Float(val)
      when :Array;   Array(val)
      when :String;  String(val)
      when :Symbol;  String(val).intern
      else val end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.