Class: Hashie::Clash

### Home Classes Methods

### In Files

- lib/hashie/clash.rb

### Parent

Hash

### Namespace

- CLASS Hashie::Clash::ChainError

### Methods

- ::new
- #_end!

### Class/Module Index

Quicksearch

- Hashie
- Hashie::Clash
- Hashie::Clash::ChainError
- Hashie::Dash
- Hashie::Hash
- Hashie::HashExtensions
- Hashie::Mash
- Hashie::PrettyInspect
- Hashie::Trash

No matching classes.

# Hashie::Clash

A Clash is a "Chainable Lazy Hash". Inspired by libraries such as Arel, a Clash allows you to chain together method arguments to build a hash, something that's especially useful if you're doing something like constructing a complex options hash. Here's a basic example:

    c = Hashie::Clash.new.conditions(:foo => 'bar').order(:created_at)
    c # => {:conditions => {:foo => 'bar'}, :order => :created_at}

Clash provides another way to create sub-hashes by using bang notation. You can dive into a sub-hash by providing a key with a bang and dive back out again with the _end! method. Example:

    c = Hashie::Clash.new.conditions!.foo('bar').baz(123)._end!.order(:created_at)
    c # => {:conditions => {:foo => 'bar', :baz => 123}, :order => :created_at}

Because the primary functionality of Clash is to build options objects, all keys are converted to symbols since many libraries expect symbols explicitly for keys.

### Attributes

_parent[R]

The parent Clash if this Clash was created via chaining.

### Public Class Methods

new(other_hash = {}, parent = nil) click to toggle source

Initialize a new clash by passing in a Hash to convert and, optionally, the parent to which this Clash is chained.

    # File lib/hashie/clash.rb, line 32
    def initialize(other_hash = {}, parent = nil)
      @_parent = parent
      other_hash.each_pair do |k, v|
        self[k.to_sym] = v
      end
    end

### Public Instance Methods

_end!() click to toggle source

Jump back up a level if you are using bang method chaining. For example:

c = Hashie::Clash.new.foo('bar') c.baz!.foo(123) # => c c.baz!._end! # => c

    # File lib/hashie/clash.rb, line 45
    def _end!
      self._parent
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.