diff --git a/CHANGELOG.md b/CHANGELOG.md index 061d5af..4d22763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.3 + +Add the ability to specify the return value on BlankSlate methods + # 1.1.2 Minor change to simplify the methods that are iterated when creating the BlankSlate class. diff --git a/lib/blank_slate.rb b/lib/blank_slate.rb index fca9c95..342d94a 100644 --- a/lib/blank_slate.rb +++ b/lib/blank_slate.rb @@ -1,9 +1,9 @@ module BlankSlate - def BlankSlate(klass, &block) + def BlankSlate(klass, default_value: nil, &block) blank_slate = Class.new(klass, &block) blank_slate.class_eval do (klass.instance_methods(false) - instance_methods(false)).each do |meth| - define_method(meth){ nil } + define_method(meth){ default_value } end end blank_slate diff --git a/lib/blank_slate/version.rb b/lib/blank_slate/version.rb index e994c79..d1bdad3 100644 --- a/lib/blank_slate/version.rb +++ b/lib/blank_slate/version.rb @@ -1,3 +1,3 @@ module BlankSlate - VERSION = "1.1.2" + VERSION = "1.1.3" end diff --git a/test/blank_slate_test.rb b/test/blank_slate_test.rb index edda030..6a99488 100644 --- a/test/blank_slate_test.rb +++ b/test/blank_slate_test.rb @@ -61,4 +61,9 @@ def one null_object = blank_slate.new assert_equal null_object.inherited, 'this should be inherited' end + + it "uses the specified default_value for the return" do + null_object = BlankSlate(BlankSlate::TesterClass, default_value: "blank").new + assert_equal "blank", null_object.one + end end