Skip to content

Commit

Permalink
Add ability to specify default value
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Jul 12, 2022
1 parent c585da0 commit aa1b8a7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/blank_slate.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/blank_slate/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BlankSlate
VERSION = "1.1.2"
VERSION = "1.1.3"
end
5 changes: 5 additions & 0 deletions test/blank_slate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aa1b8a7

Please sign in to comment.