Permalink
Browse files

derp

  • Loading branch information...
1 parent d0a8644 commit 88bb9d9c9358449cd450035f82e37a4d64a8bb2e @lukaszkorecki committed May 27, 2012
Showing with 49 additions and 1 deletion.
  1. +1 −1 lib/super-envy.rb
  2. +29 −0 lib/super-envy/extender.rb
  3. +18 −0 spec/behaviour_spec.rb
  4. +1 −0 spec/spec_helper.rb
View
2 lib/super-envy.rb
@@ -1,5 +1,5 @@
require "super-envy/version"
+require "super-envy/extender"
module SuperEnvy
- # Your code goes here...
end
View
29 lib/super-envy/extender.rb
@@ -0,0 +1,29 @@
+module SuperEnvy
+ class Extender
+
+ def initialize hash
+ @hash = hash
+ can_be_upgraded?
+ create_accessors!
+
+ end
+
+ private
+ def can_be_upgraded?
+ raise "This object is not a hash!" unless @hash.is_a? Hash
+ end
+
+ def create_accessors!
+ @hash.keys.map {|k| [k.to_s.gsub('-', '_').to_sym , k ] }.each do |d,e|
+
+ puts d.inspect
+ puts e.inspect
+ name, original_key = d
+ puts "definiingin method: #{name}"
+ puts "with keyj #{original_key}"
+ puts "and value #{@hash[original_key]}"
+ define_method name { @hash[original_key] }
+ end
+ end
+ end
+end
View
18 spec/behaviour_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe 'Top-level wrapper' do
+
+ it 'can be attached to any hash instance' do
+ h = {:hi => 'how are you'}
+
+ e = SuperEnvy::Extender.new h
+
+ e.should respond_to :hi
+
+ end
+
+
+ it 'throws an exception if it doesnt receive a hash' do
+ expect { SuperEnvy::Extender.new "lol"}.should raise_error
+ end
+end
View
1 spec/spec_helper.rb
@@ -0,0 +1 @@
+require './lib/super-envy'

0 comments on commit 88bb9d9

Please sign in to comment.