Module: Hashie::Extensions::MethodWriter

### Home Classes Methods

### In Files

- lib/hashie/extensions/method_access.rb

### Methods

- #convert_key
- #method_missing
- #respond_to?

### Class/Module Index

Quicksearch

- Hashie
- Hashie::Clash
- Hashie::Clash::ChainError
- Hashie::CoercionError
- Hashie::Dash
- Hashie::Extensions
- Hashie::Extensions::Coercion
- Hashie::Extensions::Coercion::ClassMethods
- Hashie::Extensions::Coercion::InstanceMethods
- Hashie::Extensions::Dash
- Hashie::Extensions::Dash::IndifferentAccess
- Hashie::Extensions::Dash::IndifferentAccess::ClassMethods
- Hashie::Extensions::DeepFetch
- Hashie::Extensions::DeepFetch::UndefinedPathError
- Hashie::Extensions::DeepFind
- Hashie::Extensions::DeepMerge
- Hashie::Extensions::IgnoreUndeclared
- Hashie::Extensions::IndifferentAccess
- Hashie::Extensions::KeyConversion
- Hashie::Extensions::Mash
- Hashie::Extensions::Mash::SafeAssignment
- Hashie::Extensions::MergeInitializer
- Hashie::Extensions::MethodAccess
- Hashie::Extensions::MethodAccessWithOverride
- Hashie::Extensions::MethodOverridingWriter
- Hashie::Extensions::MethodQuery
- Hashie::Extensions::MethodReader
- Hashie::Extensions::MethodWriter
- Hashie::Extensions::Parsers
- Hashie::Extensions::Parsers::YamlErbParser
- Hashie::Extensions::PrettyInspect
- Hashie::Extensions::StringifyKeys
- Hashie::Extensions::StringifyKeys::ClassMethods
- Hashie::Extensions::SymbolizeKeys
- Hashie::Extensions::SymbolizeKeys::ClassMethods
- Hashie::Hash
- Hashie::Mash
- Hashie::Rash
- Hashie::Trash

No matching classes.

# Hashie::Extensions::MethodWriter

MethodWriter gives you key_name= shortcuts for writing to your hash. Keys are written as strings, override convert_key if you would like to have symbols or something else.

Note that MethodWriter also overrides respond_to such that any method_name= will respond appropriately as true.

@example

    class MyHash < Hash
      include Hashie::Extensions::MethodWriter
    end

    h = MyHash.new
    h.awesome = 'sauce'
    h['awesome'] # => 'sauce'

### Public Instance Methods

convert_key(key) click to toggle source

    # File lib/hashie/extensions/method_access.rb, line 83
    def convert_key(key)
      key.to_s
    end

method_missing(name, *args) click to toggle source

    # File lib/hashie/extensions/method_access.rb, line 75
    def method_missing(name, *args)
      if args.size == 1 && name.to_s =~ /(.*)=$/
        return self[convert_key(Regexp.last_match[1])] = args.first
      end

      super
    end

respond_to?(name, include_private = false) click to toggle source

    # File lib/hashie/extensions/method_access.rb, line 70
    def respond_to?(name, include_private = false)
      return true if name.to_s =~ /=$/
      super
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.