class Object
coding:utf-8
Public Instance Methods
apply_opts(opts)
click to toggle source
# File lib/rdoba/common.rb, line 33 def apply_opts(opts) parse_opts(opts).each do |x,y| self.instance_variable_set("@#{x}".to_sym, y) end end
co(method, *args)
click to toggle source
# File lib/rdoba/common.rb, line 10 def co(method, *args) #calls any method eval "#{method}(*args)" end
parse_opts(opts)
click to toggle source
# File lib/rdoba/common.rb, line 18 def parse_opts(opts) v = {} opts.each do |opt| case opt.class.to_s.to_sym when :Hash opt.each do |x,y| v[x] = y end when :Array opt.each do |x| v[x] = true end when :Symbol v[opt] = true end end v end
to_sym()
click to toggle source
# File lib/rdoba/common.rb, line 14 def to_sym to_s.to_sym end
to_yml( o = {} )
click to toggle source
# File lib/rdoba/yaml.rb, line 6 def to_yml( o = {} ) level = o[:level] || 0 res = '' res += '---' if level == 0 res += case self.class.to_sym when :Hash rs = '' self.keys.sort do |x,y| (ix, iy) = o[:order] ? [ o[:order].index(x), o[:order].index(y) ] : [ nil, nil ] (ix and iy) ? ix <=> iy : (ix ? -1 : (iy ? 1 : x <=> y)) end.each do |key| value = self[key] rs += "\n" + ' ' * level * 2 + key.to_yml( { :level => level + 1, :order => o[:order] } ) rs += ': ' + value.to_yml( { :level => level + 1, :order => o[:order] } ) end rs.empty? and "{}" or rs when :Array rs = '' self.each do |value| rs += "\n" + ' ' * level * 2 + '- ' + value.to_yml( { :level => level + 1, :order => o[:order] } ) end rs.empty? and "[]" or rs when :Fixnum self.to_s when :String if self =~ /^["'\-:!#={}\[\]~]/ or self =~ /\s+$/ or self =~ /:\s/ if self.count("'") < self.count('"') "'#{self.gsub("'","\\'")}'" else "\"#{self.gsub('"','\"')}\"" end else self end when :NilClass '' else $stderr.puts "Unsupported class #{self.class} to export to yml"; '' end res end
xor(val1)
click to toggle source
# File lib/rdoba/common.rb, line 5 def xor(val1) val0 = (not not self) ((val0) and (not val1)) or ((not val0) and (val1)) end