Skip to content

Commit

Permalink
Merge pull request #47 from sferik/document_predicates_return
Browse files Browse the repository at this point in the history
Document predicates_return
  • Loading branch information
Avdi Grimm committed Jan 10, 2014
2 parents 3ad13c6 + 1c71816 commit ddeab5a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ null.foo.bar.baz # => <null>
null << "hello" << "world" # => <null>
```
### What's that "config" thing?
#### What's that "config" thing?
That's what you use to customize the generated class to your
liking. Internally, Naught uses the [Builder
Expand Down Expand Up @@ -205,6 +205,23 @@ end
# >> Yep, checks out!
```

#### What about predicate methods? You know, the ones that end with question marks? Shouldn't they return `false` instead of `nil`?

Sure, if you'd like.
```ruby
require 'naught'
NullObject = Naught.build do |config|
config.predicates_return false
end
null = NullObject.new
null.foo # => nil
null.bar? # => false
null.nil? # => false
```
#### Alright smartypants. What if I want to add my own methods?
Not a problem, just define them in the `.build` block.
Expand All @@ -214,6 +231,7 @@ require 'naught'
NullObject = Naught.build do |config|
config.define_explicit_conversions
config.predicates_return false
def to_path
"/dev/null"
end
Expand All @@ -222,11 +240,16 @@ NullObject = Naught.build do |config|
def to_s
"NOTHING TO SEE HERE MOVE ALONG"
end
def nil?
true
end
end
null = NullObject.new
null.to_s # => "NOTHING TO SEE HERE MOVE ALONG"
null.to_path # => "/dev/null"
null.to_s # => "NOTHING TO SEE HERE MOVE ALONG"
null.nil? # => true
```
#### Got anything else up your sleeve?
Expand Down

0 comments on commit ddeab5a

Please sign in to comment.