Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got HashWithName working with initializing through []

  • Loading branch information...
commit 9276b0d9f0a66c1465e35f3676183eec20a8eb3d 1 parent db3ddb1
Mark Evans markevans authored
6 lib/dragonfly/hash_with_name.rb
@@ -5,6 +5,12 @@ module Dragonfly
5 5 # updating ext/basename also updates the name
6 6 class HashWithName < Hash
7 7
  8 + def self.[](hash)
  9 + new_hash = super
  10 + new_hash[:name] = hash[:name] if hash[:name] # Make sure the name= method gets called
  11 + new_hash
  12 + end
  13 +
8 14 def [](key)
9 15 [:name, :basename, :ext].include?(key) ? send(key) : super
10 16 end
8 spec/dragonfly/hash_with_name_spec.rb
@@ -66,4 +66,12 @@
66 66 end
67 67 end
68 68
  69 + describe "initializing with []" do
  70 + it "should still work" do
  71 + hash = Dragonfly::HashWithName[:name => 'mark.duggan']
  72 + hash[:name].should == 'mark.duggan'
  73 + hash[:ext].should == 'duggan'
  74 + end
  75 + end
  76 +
69 77 end

0 comments on commit 9276b0d

Please sign in to comment.
Something went wrong with that request. Please try again.