Class: Optionil
- Inherits:
-
Object
- Object
- Optionil
- Defined in:
- lib/optionil.rb
Class Method Summary collapse
-
.[] ⇒ nil
Take 0 args.
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #none? ⇒ Boolean
- #some?(matcher = nil, &blk) ⇒ Boolean
- #value(&blk) ⇒ Object
- #value! ⇒ Object
Class Method Details
.[] ⇒ nil
Take 0 args
7 8 9 |
# File 'lib/optionil.rb', line 7 def self.[](x = nil) x end |
Instance Method Details
#each(&blk) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/optionil.rb', line 24 def each(&blk) if blk blk.(self) unless nil? else enum_for __callee__ end end |
#none? ⇒ Boolean
35 36 37 |
# File 'lib/optionil.rb', line 35 def none?(...) !some?(...) end |
#some?(matcher = nil, &blk) ⇒ Boolean
32 33 34 |
# File 'lib/optionil.rb', line 32 def some?(matcher = nil, &blk) (matcher.nil? ? blk || Some : matcher) === self end |
#value(&blk) ⇒ Object
18 19 20 |
# File 'lib/optionil.rb', line 18 def value(&blk) nil? ? blk&.() : self end |
#value! ⇒ Object
21 22 23 |
# File 'lib/optionil.rb', line 21 def value! Some[self] end |