Top Level Namespace
Defined Under Namespace
Modules: Filigree Classes: AbstractClassError, AbstractMethodError, Array, CommandNotFoundError, MatchError
Instance Method Summary collapse
-
#check_array_type(array, type, blame: nil, nillable: false, strict: false) ⇒ Object
A method for type checking Ruby array values.
-
#check_type(obj, type, blame: nil, nillable: false, strict: false) ⇒ Object
A method for type checking Ruby values.
-
#match(*objects, &block) ⇒ Object
Result of evaluating the matched pattern’s block.
-
#request_file(file, print_failure = false) ⇒ Object
Require a file, but fail gracefully if it isn’t found.
-
#returning(value) {|value| ... } ⇒ Object
Simple implementation of the Y combinator.
Instance Method Details
#check_array_type(array, type, blame: nil, nillable: false, strict: false) ⇒ Object
A method for type checking Ruby array values.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/filigree/types.rb', line 57 def check_array_type(array, type, blame: nil, nillable: false, strict: false) array.each do |obj| type_ok = (obj.nil? && nillable) || (strict ? obj.instance_of?(type) : obj.is_a?(type)) if not type_ok if blame raise TypeError, "Parameter #{blame} must contain instances of the #{type.name} class." else raise TypeError, "Expected an object of type #{type.name}." end end end end |
#check_type(obj, type, blame: nil, nillable: false, strict: false) ⇒ Object
A method for type checking Ruby values.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/filigree/types.rb', line 30 def check_type(obj, type, blame: nil, nillable: false, strict: false) type_ok = (obj.nil? && nillable) || (strict ? obj.instance_of?(type) : obj.is_a?(type)) if type_ok obj else if blame raise TypeError, "Parameter #{blame} must be an instance of the #{type.name} class. Received an instance of #{obj.class.name}." else raise TypeError, "Expected an object of type #{type.name}. Received an instance of #{obj.class.name}." end end end |
#match(*objects, &block) ⇒ Object
Returns Result of evaluating the matched pattern’s block.
157 158 159 160 161 162 163 |
# File 'lib/filigree/match.rb', line 157 def match(*objects, &block) me = Filigree::MatchEnvironment.new me.instance_exec(&block) me.find_match(objects) end |
#request_file(file, print_failure = false) ⇒ Object
Require a file, but fail gracefully if it isn’t found. If a block is given it will be called if the file is successfully required.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/filigree/request_file.rb', line 23 def request_file(file, print_failure = false) begin require file yield if block_given? rescue LoadError if print_failure.is_a?(String) puts print_failure elsif print_failure puts "Unable to require file: #{file}" end end end |
#returning(value) {|value| ... } ⇒ Object
Simple implementation of the Y combinator.
23 24 25 26 |
# File 'lib/filigree/object.rb', line 23 def returning(value) yield(value) value end |