Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Got HashWithName working with initializing through []

  • Loading branch information...
commit 9276b0d9f0a66c1465e35f3676183eec20a8eb3d 1 parent db3ddb1
@markevans markevans authored
View
6 lib/dragonfly/hash_with_name.rb
@@ -5,6 +5,12 @@ module Dragonfly
# updating ext/basename also updates the name
class HashWithName < Hash
+ def self.[](hash)
+ new_hash = super
+ new_hash[:name] = hash[:name] if hash[:name] # Make sure the name= method gets called
+ new_hash
+ end
+
def [](key)
[:name, :basename, :ext].include?(key) ? send(key) : super
end
View
8 spec/dragonfly/hash_with_name_spec.rb
@@ -66,4 +66,12 @@
end
end
+ describe "initializing with []" do
+ it "should still work" do
+ hash = Dragonfly::HashWithName[:name => 'mark.duggan']
+ hash[:name].should == 'mark.duggan'
+ hash[:ext].should == 'duggan'
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.