class Object
Copyright Freya Dorn <freya.siv.dorn@gmail.com>, 2017 License: GNU APGLv3 (or later) <www.gnu.org/copyleft/gpl.html>
defaults
Copyright Freya Dorn <freya.siv.dorn@gmail.com>, 2017 License: GNU APGLv3 (or later) <www.gnu.org/copyleft/gpl.html>
Public Instance Methods
blank?()
click to toggle source
# File lib/muflax/blank.rb, line 12 def blank? ; false ; end
bp()
click to toggle source
This is very stupid and shouldn’t be used in real code, which is why I will use it in real code.
# File lib/muflax/debug.rb, line 8 def bp require "debug_inspector" require "pry" RubyVM::DebugInspector.open do |inspector| eval("binding.pry", inspector.frame_binding(2)) end end
bpe()
click to toggle source
# File lib/muflax/debug.rb, line 16 def bpe require "debug_inspector" require "pry" RubyVM::DebugInspector.open do |inspector| eval("binding.pry; exit", inspector.frame_binding(2)) end end
deep_dup()
click to toggle source
# File lib/muflax/deep_dup.rb, line 7 def deep_dup duplicable? ? dup : self end
differences_with(other)
click to toggle source
# File lib/muflax/objects.rb, line 41 def differences_with(other) # get list of all attributes attrs = (self.class.attr_readers + self.class.attr_writers).uniq.sort # pick all attributes that they disagree about attrs.reject do |attr| self.respond_to? attr and other.respond_to? attr and self.send(attr) == other.send(attr) end end
duplicable?()
click to toggle source
# File lib/muflax/deep_dup.rb, line 35 def duplicable? ; true ; end
in?(other)
click to toggle source
# File lib/muflax/enumerable.rb, line 70 def in? other other.include?(self) rescue NoMethodError raise ArgumentError.new("The parameter passed to #in? must respond to #include?") end
nil_if_blank()
click to toggle source
# File lib/muflax/blank.rb, line 8 def nil_if_blank ; self.blank? ? nil : self ; end
present?()
click to toggle source
# File lib/muflax/blank.rb, line 7 def present? ; !blank? ; end
require_local(lib_name, location=caller_locations.first.path)
click to toggle source
Copyright Freya Dorn <freya.siv.dorn@gmail.com>, 2013 License: GNU GPL 3 <www.gnu.org/copyleft/gpl.html>
# File lib/muflax/library.rb, line 6 def require_local lib_name, location=caller_locations.first.path file = File.symlink?(location) ? File.readlink(location) : location dir = File.dirname(file) lib = File.join(dir, "#{lib_name}.rb") raise "couldn't find local module: «#{lib_name}» in «#{dir}»" if not File.exist? lib require lib end
require_local_libs(path, location=__FILE__)
click to toggle source
# File lib/muflax.rb, line 21 def require_local_libs path, location=__FILE__ Dir["#{File.join(File.dirname(location), path)}/*.rb"].each do |lib| require lib end end
stop_here()
click to toggle source
# File lib/muflax/debug.rb, line 33 def stop_here warn "[END OF DEBUG]" exit end
str_length()
click to toggle source
consistent string length
# File lib/muflax/align.rb, line 28 def str_length s = self.to_s ss = StringScanner.new(s) len = s.length len -= ss.matched_size while ss.skip_until(String::ANSIColorRegexp) len end
v(*variables)
click to toggle source
# File lib/muflax/debug.rb, line 24 def v *variables require "debug_inspector" RubyVM::DebugInspector.open do |inspector| variables.each do |variable| eval("print '#{variable}: '; ap #{variable}", inspector.frame_binding(2)) end end end
vivaHash(default=[])
click to toggle source
simple auto-vivifying hash TODO support nested hashes
# File lib/muflax/hash.rb, line 8 def vivaHash default=[] hash = if default.duplicable? ; Hash.new{|h, k| h[k] = default.dup} else ; Hash.new{|h, k| h[k] = default} end hash end