module Filigree
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Classes and Modules #
Author: Chris Wailes <chris.wailes+filigree@gmail.com> Project: Filigree
Date: 2013/4/19 Description: This file specifies the version number of Filigree
.
Classes and Modules #
Constants
- VERSION
Public Class Methods
Wrap non-pattern objects in pattern objects so they can all be treated in the same way during pattern sorting and matching.
@param [Array<Object>] pattern Naked pattern object
@return [Array<BasicPattern>] Wrapped pattern object
# File lib/filigree/match.rb, line 179 def Filigree::wrap_pattern_elements(pattern) pattern.map do |el| case el when BasicPattern then el when Class then InstancePattern.new(el) when Regexp then RegexpPattern.new(el) else LiteralPattern.new(el) end end end
Public Instance Methods
Causes an instance of a class to be bound the the given name.
@param [BindingPattern] binding_pattern Name to bind the instance to
# File lib/filigree/match.rb, line 647 def as(binding_pattern) binding_pattern.tap { |bp| bp.pattern_elem = Filigree::InstancePattern.new(self) } end
A copy and modification helper.
@return [Object] A copy of the object with the block evaluated in the context of the copy.
# File lib/filigree/object.rb, line 39 def clone_with(&block) self.clone.tap { |clone| clone.instance_exec(&block) } end
Checks for module inclusion.
@param [Module] mod Module to check the inclusion of.
@return [Boolean] If the module was included
# File lib/filigree/class.rb, line 27 def includes_module?(mod) self.included_modules.include?(mod) end
Chop up the string into multiple lines so that no line is longer than the specified number of characters.
@param [Fixnum] indent Indentation to put before each line; it is
assumed that this indentation is already present for the first line
@param [Fixnum] max_length Maximum length per line
# File lib/filigree/string.rb, line 26 def segment(indent, max_length = 80) lines = Array.new words = self.split(/\s/) line = words.shift line_length = indent + line.length words.each do |word| new_length = line_length + 1 + word.length if new_length < max_length line += " #{word}" line_length = new_length else lines << line line = word line_length = indent + word.length end end lines << line unless line.empty? lines.join("\n" + (' ' * indent)) end
@return [String] Name of class without the namespace.
# File lib/filigree/class.rb, line 32 def short_name self.name.split('::').last end
Checks to see if a Class object is a subclass of the given class.
@param [Class] klass Class we are checking if this is a subclass of.
@return [Boolean] If self is a subclass of klass
# File lib/filigree/class.rb, line 41 def subclass_of?(klass) check_type(klass, Class, blame: 'klass') if (superklass = self.superclass) superklass == klass or superklass.subclass_of?(klass) else false end end
@return [Boolean] This Integer as a Boolean value.
# File lib/filigree/boolean.rb, line 23 def to_bool self != 0 end
@return [1]
# File lib/filigree/boolean.rb, line 31 def to_i 1 end
Turns a symbol into a binding pattern.
@return [Filigree::BindingPattern]
# File lib/filigree/match.rb, line 666 def ~ Filigree::BindingPattern.new(self) end