Commit 31da2f7

mo khan <mo@mokhan.ca>
2013-12-27 17:14:36
add module to expose an objects binding.
1 parent 65d46c9
Changed files (3)
lib/nasty/binding_behaviour.rb
@@ -0,0 +1,7 @@
+module Nasty
+  module BindingBehaviour
+    def get_binder
+      binding
+    end
+  end
+end
lib/nasty.rb
@@ -1,4 +1,5 @@
 require "nasty/background_job"
+require "nasty/binding_behaviour"
 require "nasty/command"
 require "nasty/composite_command"
 require "nasty/kernel"
spec/unit/binding_spec.rb
@@ -0,0 +1,16 @@
+require "spec_helper"
+
+module Nasty
+  describe BindingBehaviour do
+    it "exposes an objects private binding" do
+      item = Object.new
+      item.instance_eval do
+        @message = "secret"
+      end
+      item.extend(Nasty::BindingBehaviour)
+      binding = item.get_binder
+      result = ERB.new("<%= @message %>").result(binding)
+      result.should == "secret"
+    end
+  end
+end