README.md in nil_conditional-0.0.1 vs README.md in nil_conditional-1.0.0
- old
+ new
@@ -1,50 +1,77 @@
# nil-conditional
Nil Conditional Operator in Ruby.
-## Summary
+This is my approach to create Nil Conditional Operator in Ruby.
-This gem introduces Nil Conditional Operator (`_?`) in Ruby, similar to Null Conditional Operator in C# 6.0.
+This is very simple, and it is merely an experiment, so use it on your own risk.
+Nil Conditional Operator is inspired by Null Conditional Operator introduced in C# 6.0.
+
+
## Installation
-Add this line to your application's Gemfile:
+`nil_conditional` is gemified and available on RubyGems.
+
+## Usage
+
+Use preceding double underscore (`__`) for methods (for ex. `__method`)
+Use preceding double underscore and trailing block for local variables (for ex. `__var{}`)
+
```ruby
-gem 'nil_conditional'
-```
-And then execute:
+# logger is nil
+logger.foo.bar.car.cow
+NoMethodError: undefined method `foo` for #<NilClass>
- $ bundle
+# logger is nil or doesn't exist
+__logger{}.foo.bar.car.cow
+=> #<NilConditional>
-Or install it yourself as:
+# object exists and all methods are valid
+__object{}.foo.bar.car.cow
+=> "moooo"
- $ gem install nil_conditional
+# logger exists but doesn't have warn method
+logger.__warn('some warning')
+=> #<NilConditional>
-## Usage
+__non_existent_local_variable{}
+=> #<NilConditional>
-```ruby
-empty_object = Object.new
-empty_object.non_existent_method_?
-=> nil
+__non_existent_method
+=> #<NilConditional>
-empty_object_?
-=> #<Object:0x00000002d89170>
+Object.new.non_existent_method
+NoMethodError: undefined method `non_existent_method` for #<Object>
-non_existent_object_?
-=> nil
+Object.new.__non_existent_method
+=> #<NilConditional>
-"test_string".sub_?("_string", '_case')
-=> "test_case"
+Object.new.__non_existent_method.nil?
+=> true
-:test_string.sub_?("string", "case")
+__new_object.foo.bar.car_?.cow_?
=> nil
-
-Object.foo_?.bar_?.car_?.cow_?
-=> nil
```
+
+`NilConditional` instanced return always new NilConditional object if method is missing.
+These objects are also `eql` to `nil`.
+
+
+## Changelog
+
+* Changes from version with major 0
+
+ Previous version didn't support methods with special characters and there was no support for local variables
+ Previous version used trailing `_?` as NilConditional operator. Current version uses preceding double underscore character `__`.
+
+
+## Discussion
+
+Feel free to submit ideas via issues and discuss better solution to Nil Conditional Operator in Ruby
## License
This is free software, licensed under MIT License. See LICENSE.txt file.