hexx 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +5 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -63
- data/.travis.yml +5 -0
- data/.yardopts +2 -0
- data/Gemfile +3 -0
- data/Guardfile +16 -0
- data/{LICENSE.rdoc → LICENSE} +2 -2
- data/README.md +138 -0
- data/Rakefile +8 -14
- data/config/initializer.rb +5 -0
- data/config/initializers/capture.rb +19 -0
- data/config/initializers/sandbox.rb +16 -0
- data/config/initializers/sandbox/helpers.rb +38 -0
- data/config/initializers/sandbox/matchers.rb +19 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +15 -0
- data/config/metrics/pippi.yml +3 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +79 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +6 -0
- data/config/metrics/yardstick.yml +37 -0
- data/hexx.gemspec +24 -0
- data/lib/hexx.rb +8 -15
- data/lib/hexx/generator.rb +71 -0
- data/lib/hexx/generator/file.rb +83 -0
- data/lib/hexx/generator/folder.rb +68 -0
- data/lib/hexx/name.rb +122 -46
- data/lib/hexx/version.rb +6 -5
- data/spec/fixtures/root/_.beta +1 -0
- data/spec/fixtures/root/__omega +0 -0
- data/spec/fixtures/root/delta.erb.erb +0 -0
- data/spec/fixtures/root/gamma.rb.erb +1 -0
- data/spec/fixtures/root/subfolder/alfa.yml +0 -0
- data/spec/spec_helper.rb +5 -10
- data/spec/tests/lib/generator_spec.rb +126 -0
- data/spec/tests/lib/name_spec.rb +113 -0
- metadata +54 -168
- data/README.rdoc +0 -371
- data/lib/hexx/coercible.rb +0 -43
- data/lib/hexx/configurable.rb +0 -101
- data/lib/hexx/creators/base.rb +0 -103
- data/lib/hexx/creators/coercion.rb +0 -82
- data/lib/hexx/creators/dependency.rb +0 -87
- data/lib/hexx/creators/module_dependency.rb +0 -57
- data/lib/hexx/creators/parameter.rb +0 -40
- data/lib/hexx/dependable.rb +0 -51
- data/lib/hexx/helpers/exceptions.rb +0 -53
- data/lib/hexx/helpers/messages.rb +0 -26
- data/lib/hexx/helpers/parameters.rb +0 -47
- data/lib/hexx/helpers/validations.rb +0 -21
- data/lib/hexx/message.rb +0 -79
- data/lib/hexx/null.rb +0 -218
- data/lib/hexx/service.rb +0 -388
- data/lib/hexx/service/with_callbacks.rb +0 -104
- data/lib/hexx/service_invalid.rb +0 -73
- data/spec/hexx/coercible_spec.rb +0 -72
- data/spec/hexx/configurable_spec.rb +0 -93
- data/spec/hexx/dependable_spec.rb +0 -125
- data/spec/hexx/helpers/exceptions_spec.rb +0 -96
- data/spec/hexx/helpers/messages_spec.rb +0 -48
- data/spec/hexx/helpers/parameters_spec.rb +0 -96
- data/spec/hexx/helpers/validations_spec.rb +0 -32
- data/spec/hexx/message_spec.rb +0 -83
- data/spec/hexx/name_spec.rb +0 -80
- data/spec/hexx/null_spec.rb +0 -152
- data/spec/hexx/service_invalid_spec.rb +0 -46
- data/spec/hexx/service_spec.rb +0 -89
- data/spec/support/initializers/focus.rb +0 -5
- data/spec/support/initializers/garbage_collection.rb +0 -11
- data/spec/support/initializers/i18n.rb +0 -3
- data/spec/support/initializers/random_order.rb +0 -4
- data/spec/support/initializers/rspec.rb +0 -5
- data/spec/support/matchers/methods.rb +0 -11
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "base"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
module Creators
|
6
|
-
|
7
|
-
# @api hide
|
8
|
-
# Adds setter and getter for the instance parameter.
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# # Providing that MyClass#params returns a hash
|
12
|
-
# Parameter.add MyClass, :name
|
13
|
-
# object = MyClass.new
|
14
|
-
#
|
15
|
-
# object.params["name"] # => nil
|
16
|
-
# object.name # => nil
|
17
|
-
#
|
18
|
-
# object.params["name"] = "Ivan"
|
19
|
-
# object.params["name"] # => "Ivan"
|
20
|
-
# object.name # => "Ivan"
|
21
|
-
#
|
22
|
-
# object.name = "Ivo"
|
23
|
-
# object.params["name"] # => "Ivo"
|
24
|
-
# object.name # => "Ivo"
|
25
|
-
class Parameter < Base
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
# @api hide
|
30
|
-
def setter
|
31
|
-
"private def #{ name }; params[\"#{ name }\"]; end"
|
32
|
-
end
|
33
|
-
|
34
|
-
# @api hide
|
35
|
-
def getter
|
36
|
-
"private def #{ name }=(value); params[\"#{ name }\"] = value; end"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/hexx/dependable.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# Makes the class dependable from implementations through setter injections.
|
6
|
-
#
|
7
|
-
# Adds the private {#depends_on} helper method to the class.
|
8
|
-
# Basically the method is similar to the +attr_accessor+ with the following
|
9
|
-
# differencies:
|
10
|
-
#
|
11
|
-
# * it adds a semantics to the declaration.
|
12
|
-
# * it allows setting the default implementation.
|
13
|
-
# * dependency setters accepts classes and modules only and fails with
|
14
|
-
# the +TypeError+ otherwise.
|
15
|
-
# * dependency getters fails with the +NotImplemented+ error if the
|
16
|
-
# implementation hasn't been set.
|
17
|
-
# * if a default implementation is defined, the dependency cannot be
|
18
|
-
# set to +nil+.
|
19
|
-
#
|
20
|
-
# @example
|
21
|
-
# class MyClass
|
22
|
-
# extend Hexx::Dependable
|
23
|
-
#
|
24
|
-
# depends_on :another_class, default: AnotherClass
|
25
|
-
# depends_on :looks_for_implementation
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# object = MyClass.new
|
29
|
-
# object.another_class # => AnotherClass
|
30
|
-
#
|
31
|
-
# object.looks_for_implementation
|
32
|
-
# # => fails with NotImplementedError
|
33
|
-
#
|
34
|
-
# object.looks_for_implementation = SomeInjection
|
35
|
-
# object.looks_for_implementation # => SomeInjection
|
36
|
-
module Dependable
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# @!method depends_on(name, options = {})
|
41
|
-
# Declares the dependency with its default implementation.
|
42
|
-
# @example (see Hexx::Dependable)
|
43
|
-
# @param [String, Symbol] name The name of the dependency.
|
44
|
-
# @param [Hash] options ({}) The dependency declaration options.
|
45
|
-
# @option options [String, Symbol, Class] :default (nil) Optional default
|
46
|
-
# implementation for the dependency.
|
47
|
-
def depends_on(name, default: nil)
|
48
|
-
Creators::Dependency.add self, name, default
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "messages"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
module Helpers
|
6
|
-
|
7
|
-
# @api hide
|
8
|
-
# The module declares instance helper methods to provide validations
|
9
|
-
module Exceptions
|
10
|
-
extend ActiveSupport::Concern
|
11
|
-
include ActiveModel::Validations
|
12
|
-
include Messages
|
13
|
-
|
14
|
-
# @api hide
|
15
|
-
# Class helper methods
|
16
|
-
module ClassMethods
|
17
|
-
|
18
|
-
def raises(*names)
|
19
|
-
fail ArgumentError if (types = names.flatten.map(&:to_s)) == []
|
20
|
-
types.each { |type| add_exception(type) }
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def add_exception(type)
|
26
|
-
check type
|
27
|
-
class_eval "class #{ type } < StandardError; end"
|
28
|
-
end
|
29
|
-
|
30
|
-
def check(type)
|
31
|
-
return if type[/([A-Z][a-z]+)+/]
|
32
|
-
fail TypeError.new(
|
33
|
-
%(Wrong exception name "#{ type }". Use words in camel-case only.)
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def on_error(messages)
|
39
|
-
messages.map(&:text).each { |text| errors.add :base, text }
|
40
|
-
fail Hexx::ServiceInvalid.new(self)
|
41
|
-
end
|
42
|
-
|
43
|
-
def escape
|
44
|
-
yield
|
45
|
-
rescue Hexx::ServiceInvalid => err
|
46
|
-
raise err
|
47
|
-
rescue => err
|
48
|
-
errors.add :base, err.message
|
49
|
-
raise Hexx::ServiceInvalid.new(self)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
module Helpers
|
5
|
-
|
6
|
-
# @api hide
|
7
|
-
# The module provides helper methods to add and return service messages.
|
8
|
-
module Messages
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
def t(text, options = {})
|
12
|
-
return text unless text.is_a? Symbol
|
13
|
-
scope = %w(activemodel messages models) << self.class.name.underscore
|
14
|
-
I18n.t text, options.merge(scope: scope)
|
15
|
-
end
|
16
|
-
|
17
|
-
def messages
|
18
|
-
@messages ||= []
|
19
|
-
end
|
20
|
-
|
21
|
-
def add_message(type, text, options = {})
|
22
|
-
messages << Hexx::Message.new(type: type, text: t(text, options))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# @api hide
|
6
|
-
# The module contains classes that defines helper methods for the service.
|
7
|
-
#
|
8
|
-
# Basically those methods are private inside the service. In the helper
|
9
|
-
# they are public, allowing them to be testable as a part of the gem's API.
|
10
|
-
module Helpers
|
11
|
-
|
12
|
-
# @api hide
|
13
|
-
# The module declares helper methods for managing service object's params.
|
14
|
-
module Parameters
|
15
|
-
extend ActiveSupport::Concern
|
16
|
-
|
17
|
-
# @api hide
|
18
|
-
# Class helper methods
|
19
|
-
module ClassMethods
|
20
|
-
|
21
|
-
def allow_params(*keys)
|
22
|
-
@params = keys.flatten.map(&:to_s)
|
23
|
-
fail ArgumentError if @params == []
|
24
|
-
params.each { |name| Creators::Parameter.add self, name }
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def params
|
30
|
-
@params ||= []
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
attr_reader :params
|
35
|
-
|
36
|
-
def initialize(params = {})
|
37
|
-
@params = params.stringify_keys.slice(*class_params)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def class_params
|
43
|
-
@class_params ||= self.class.send :params
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "messages"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
module Helpers
|
6
|
-
|
7
|
-
# @api hide
|
8
|
-
# The module declares instance helper methods to provide validations
|
9
|
-
module Validations
|
10
|
-
extend ActiveSupport::Concern
|
11
|
-
|
12
|
-
def validate!
|
13
|
-
fail Hexx::ServiceInvalid.new(self) unless valid?
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.included(klass)
|
17
|
-
klass.send :include, ActiveModel::Validations
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/hexx/message.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
module Hexx
|
2
|
-
|
3
|
-
# A message to be returned by services.
|
4
|
-
class Message
|
5
|
-
include Comparable
|
6
|
-
|
7
|
-
# @!attribute [r] type
|
8
|
-
# The type of the message
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# message = Message.new type: :error, text: "message"
|
12
|
-
# message.type = "error"
|
13
|
-
#
|
14
|
-
# @return [String] The type of the message.
|
15
|
-
attr_reader :type
|
16
|
-
|
17
|
-
# @!attribute [r] text
|
18
|
-
# The text of the message
|
19
|
-
#
|
20
|
-
# @example
|
21
|
-
# message = Message.new type: :error, text: "message"
|
22
|
-
# message.text = "message"
|
23
|
-
#
|
24
|
-
# @return [String] The text of the message.
|
25
|
-
attr_reader :text
|
26
|
-
|
27
|
-
# @!scope class
|
28
|
-
# @!method new(options)
|
29
|
-
# Constructs the message with type and text.
|
30
|
-
#
|
31
|
-
# @example
|
32
|
-
# Message.new type: "success", text: "Object created."
|
33
|
-
#
|
34
|
-
# @param [Hash] options The list of the message attributes.
|
35
|
-
# @option options [String, Symbol] :type The type of the message.
|
36
|
-
# @option options [String, Symbol] :text The text of the message.
|
37
|
-
# @return [Hexx::Message] The message.
|
38
|
-
|
39
|
-
# @api hide
|
40
|
-
def initialize(type:, text:)
|
41
|
-
@type, @text = type.to_s, text.to_s
|
42
|
-
end
|
43
|
-
|
44
|
-
# Distinguishes two messages by type and text.
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# a = Message.new(type: "a", text: "a")
|
48
|
-
# b = Message.new(type: "a", text: "a")
|
49
|
-
# c = Message.new(type: "b", text: "a")
|
50
|
-
# d = Message.new(type: "a", text: "b")
|
51
|
-
#
|
52
|
-
# a == b # => true
|
53
|
-
# a == c # => false
|
54
|
-
# a == d # => false
|
55
|
-
#
|
56
|
-
# @param [Object] other The object for the comparison.
|
57
|
-
# @return [Boolean] The result of the comparison.
|
58
|
-
def ==(other)
|
59
|
-
return false unless other.is_a? self.class
|
60
|
-
[type, text] == [other.type, other.text]
|
61
|
-
end
|
62
|
-
|
63
|
-
# Compares messages by type and text.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# ab = Message.new(type: "a", text: "b")
|
67
|
-
# ba = Message.new(type: "b", text: "a")
|
68
|
-
# ab < ba # => true
|
69
|
-
#
|
70
|
-
# @param [Object] other The object for the comparison.
|
71
|
-
# @return [-1, 0, 1] The result of the comparison if the argument is
|
72
|
-
# comparable with the message.
|
73
|
-
# @return [nil] if the result is incomparable with the message.
|
74
|
-
def <=>(other)
|
75
|
-
fail ArgumentError unless other.is_a? self.class
|
76
|
-
[type, text] <=> [other.type, other.text]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
data/lib/hexx/null.rb
DELETED
@@ -1,218 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# The Null object class.
|
6
|
-
#
|
7
|
-
# Except for some special cases (see examples below) calling any method
|
8
|
-
# returns the +Null+ itself.
|
9
|
-
#
|
10
|
-
# @note (see Hexx::Null.!)
|
11
|
-
# @example (see Hexx::Null.method_missing)
|
12
|
-
# @example (see Hexx::Null.new)
|
13
|
-
# @example (see Hexx::Null.nil?)
|
14
|
-
# @example (see Hexx::Null.eq?)
|
15
|
-
# @example (see Hexx::Null.<=>)
|
16
|
-
# @example (see Hexx::Null.false?)
|
17
|
-
# @example (see Hexx::Null.true?)
|
18
|
-
# @example (see Hexx::Null.!)
|
19
|
-
# @example (see Hexx::Null.to_a)
|
20
|
-
# @example (see Hexx::Null.to_h)
|
21
|
-
# @example (see Hexx::Null.to_s)
|
22
|
-
# @example (see Hexx::Null.to_i)
|
23
|
-
# @example (see Hexx::Null.to_f)
|
24
|
-
# @example (see Hexx::Null.to_c)
|
25
|
-
# @example (see Hexx::Null.to_r)
|
26
|
-
# @example (see Hexx::Null.to_nil)
|
27
|
-
class Null
|
28
|
-
class << self
|
29
|
-
include Comparable
|
30
|
-
|
31
|
-
# The constructor constructs itself.
|
32
|
-
#
|
33
|
-
# @example The +Null+ object constructs itself.
|
34
|
-
# Null.new
|
35
|
-
# # => Null
|
36
|
-
#
|
37
|
-
# @return [Class] +Null+.
|
38
|
-
def new
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
# Checks if +Null+ is equal to other object.
|
43
|
-
#
|
44
|
-
# @example The +Null+ is equal to +nil+.
|
45
|
-
# Null.eq? nil # => true
|
46
|
-
# Null.eq? Null # => true
|
47
|
-
#
|
48
|
-
# @example The +Null+ differs from non-nil
|
49
|
-
# Null.eq? 0 # => false
|
50
|
-
# Null.eq? false # => false
|
51
|
-
#
|
52
|
-
# @param [Object] other The other object to compare to Null.
|
53
|
-
# @return [Boolean] The result of comparison.
|
54
|
-
def eq?(other)
|
55
|
-
other.nil?
|
56
|
-
end
|
57
|
-
|
58
|
-
# Compares the +Null+ to other object.
|
59
|
-
#
|
60
|
-
# @example The +Null+ is less than non-nil object:
|
61
|
-
# Null < 0 # => true
|
62
|
-
# Null < "" # => true
|
63
|
-
# Null < false # => true
|
64
|
-
#
|
65
|
-
# @param [Object] other The other object to compare to Null.
|
66
|
-
# @return [-1, 0] The result of comparison.
|
67
|
-
def <=>(other)
|
68
|
-
other.nil? ? 0 : -1
|
69
|
-
end
|
70
|
-
|
71
|
-
# Checks if the +Null+ is nil.
|
72
|
-
#
|
73
|
-
# @example The +Null+ is nil.
|
74
|
-
# Null.nil? # => true
|
75
|
-
#
|
76
|
-
# @return [Boolean] +true+.
|
77
|
-
def nil?
|
78
|
-
true
|
79
|
-
end
|
80
|
-
|
81
|
-
# Checks if the +Null+ is falseу.
|
82
|
-
#
|
83
|
-
# @example The +Null+ is falseу.
|
84
|
-
# Null.false? # => true
|
85
|
-
#
|
86
|
-
# @example The +Null+ isn't false in logical operations
|
87
|
-
# false || Null # => Null
|
88
|
-
#
|
89
|
-
# @return [Boolean] +true+.
|
90
|
-
def false?
|
91
|
-
true
|
92
|
-
end
|
93
|
-
|
94
|
-
# Converts nil to true.
|
95
|
-
#
|
96
|
-
# @note In Ruby the only objects that are +false+ are +nil+ and +false+.
|
97
|
-
# Use the double bang before any object that may be the +Null+.
|
98
|
-
#
|
99
|
-
# @example The +Null+ is convertible to +true+.
|
100
|
-
# !Null # => true
|
101
|
-
#
|
102
|
-
# @example Use a double bang before objects that may be the +Null+.
|
103
|
-
# Null && true # => true
|
104
|
-
# !!Null && true # => false
|
105
|
-
#
|
106
|
-
# @return [Boolean] +true+.
|
107
|
-
def !
|
108
|
-
true
|
109
|
-
end
|
110
|
-
|
111
|
-
# Checks if the +Null+ is truthy.
|
112
|
-
#
|
113
|
-
# @example The +Null+ isn't truthy.
|
114
|
-
# Null.true? # => false
|
115
|
-
#
|
116
|
-
# @example The +Null+ is truthy in logical operations.
|
117
|
-
# true && Null # => Null
|
118
|
-
#
|
119
|
-
# @return [Boolean] +false+.
|
120
|
-
def true?
|
121
|
-
false
|
122
|
-
end
|
123
|
-
|
124
|
-
# Converts the +Null+ to the empty string.
|
125
|
-
#
|
126
|
-
# @example The +Null+ is convertible to the empty string.
|
127
|
-
# Null.to_s # => ""
|
128
|
-
#
|
129
|
-
# @return [String] The empty string.
|
130
|
-
def to_s
|
131
|
-
""
|
132
|
-
end
|
133
|
-
|
134
|
-
# Converts the +Null+ to +nil+.
|
135
|
-
#
|
136
|
-
# @example The +Null+ is convertible to +nil+.
|
137
|
-
# Null.to_nil # => nil
|
138
|
-
#
|
139
|
-
# @return [NilClass] +nil+.
|
140
|
-
def to_nil
|
141
|
-
nil
|
142
|
-
end
|
143
|
-
|
144
|
-
# @!method to_a
|
145
|
-
# Converts the +Null+ to the empty array.
|
146
|
-
# @example The +Null+ is convertible to the empty array.
|
147
|
-
# Null.to_a # => []
|
148
|
-
# @return [Array] the empty array.
|
149
|
-
|
150
|
-
# @!method to_i
|
151
|
-
# Converts the +Null+ to zero as an integer.
|
152
|
-
# @example The +Null+ is convertible to zero as an integer.
|
153
|
-
# Null.to_i # => 0
|
154
|
-
# @return [Integer] zero.
|
155
|
-
|
156
|
-
# @!method to_f
|
157
|
-
# Converts the +Null+ to zero as a float.
|
158
|
-
# @example The +Null+ is convertible to zero as a float.
|
159
|
-
# Null.to_f # => 0.0
|
160
|
-
# @return [Float] zero.
|
161
|
-
|
162
|
-
# @!method to_c
|
163
|
-
# Converts the +Null+ to zero as a complex.
|
164
|
-
# @example The +Null+ is convertible to zero as a complex.
|
165
|
-
# Null.to_c # => (0+0i)
|
166
|
-
# @return [Complex] zero.
|
167
|
-
|
168
|
-
# @!method to_r
|
169
|
-
# Converts the +Null+ to zero as a rational.
|
170
|
-
# @example The +Null+ is convertible to zero as a rational.
|
171
|
-
# Null.to_c # => (0/1)
|
172
|
-
# @return [Rational] zero.
|
173
|
-
|
174
|
-
# Checks if a method defined.
|
175
|
-
#
|
176
|
-
# @example The +Null+ responds to any object.
|
177
|
-
# Null.respond_to? arbitrary_method
|
178
|
-
# # => true
|
179
|
-
#
|
180
|
-
# @return [Boolean] +true+.
|
181
|
-
def respond_to?(*)
|
182
|
-
true
|
183
|
-
end
|
184
|
-
|
185
|
-
# @return [false] for +Null+, +nil+ or +false+
|
186
|
-
# @return [true] otherwise.
|
187
|
-
def ^(other)
|
188
|
-
![self, nil, false].include? other
|
189
|
-
end
|
190
|
-
|
191
|
-
# @return [false] for +Null+, +nil+ or +false+
|
192
|
-
# @return [true] otherwise.
|
193
|
-
def |(other)
|
194
|
-
self.^(other)
|
195
|
-
end
|
196
|
-
|
197
|
-
private
|
198
|
-
|
199
|
-
# @api hide
|
200
|
-
# @example An arbitrary method returns the +Null+ itself.
|
201
|
-
# Null.is_an_eagle_owl? # => Null
|
202
|
-
# Null.is_an_elk? # => Null
|
203
|
-
# Null.fly # => Null
|
204
|
-
# # ... etc.
|
205
|
-
#
|
206
|
-
# @example An arbitrary method called with a block yields the block.
|
207
|
-
# Null.when_fishing { p "I've got it!" }
|
208
|
-
# # => "I've got it!"
|
209
|
-
# # => Null
|
210
|
-
#
|
211
|
-
def method_missing(name, *args, &block)
|
212
|
-
return nil.send(name, *args, &block) if nil.respond_to?(name)
|
213
|
-
block.call if block_given?
|
214
|
-
self
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|