2010-07-25 20:43:57 +00:00
|
|
|
class NilClass
|
|
|
|
def to_bool
|
|
|
|
false
|
|
|
|
end
|
2010-08-02 09:43:45 +00:00
|
|
|
|
|
|
|
def blank?
|
|
|
|
true
|
|
|
|
end
|
2010-07-25 20:43:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class String
|
|
|
|
def to_bool
|
|
|
|
%w{1 true yes}.include? self.downcase
|
|
|
|
end
|
2010-08-02 09:43:45 +00:00
|
|
|
|
|
|
|
def blank?
|
|
|
|
empty?
|
|
|
|
end
|
2020-06-28 12:02:45 +00:00
|
|
|
|
|
|
|
def to_c_string
|
|
|
|
'"' + self.gsub(%r{"}, '\"') + '"'
|
|
|
|
end
|
|
|
|
|
2022-04-22 20:06:21 +00:00
|
|
|
def to_u8_c_string
|
|
|
|
'u8' + self.to_c_string
|
|
|
|
end
|
|
|
|
|
2020-06-28 12:02:45 +00:00
|
|
|
def to_cpp_string
|
|
|
|
self.to_c_string + "s"
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_u8_cpp_string
|
|
|
|
"u8" + self.to_c_string + "s"
|
|
|
|
end
|
2010-07-25 20:43:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class TrueClass
|
|
|
|
def to_bool
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class FalseClass
|
|
|
|
def to_bool
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
2012-04-11 10:00:48 +00:00
|
|
|
|
|
|
|
class Array
|
|
|
|
def to_hash_by key = nil, value = nil, &block
|
|
|
|
elements = case
|
2015-03-24 12:20:18 +00:00
|
|
|
when block_given? then self.collect(&block)
|
2012-04-11 10:00:48 +00:00
|
|
|
when key.nil? then self.collect { |e| [ e, true ] }
|
|
|
|
else self.collect { |e| e.is_a?(Hash) ? [ e[key], value.nil? ? e : e[value] ] : [ e.send(key), value.nil? ? e : e.send(value) ] }
|
|
|
|
end
|
|
|
|
|
|
|
|
return Hash[ *elements.flatten ]
|
|
|
|
end
|
2017-04-02 19:56:30 +00:00
|
|
|
|
|
|
|
def for_target!
|
|
|
|
self.flatten!
|
|
|
|
|
2022-02-20 11:34:17 +00:00
|
|
|
reject = {
|
|
|
|
:linux => %w{ macos windows},
|
|
|
|
:macos => %w{linux windows x11},
|
|
|
|
:windows => %w{linux macos unix x11},
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:47:23 +00:00
|
|
|
# Treat other OS (e.g. FreeBSD) the same as Linux wrt. which files to compile
|
|
|
|
os = $building_for.keys.select { |key| $building_for[key] }.first
|
|
|
|
types = reject[os || :linux]
|
2022-02-20 11:34:17 +00:00
|
|
|
|
2022-04-04 16:47:23 +00:00
|
|
|
re = '(?:' + types.join('|') + ')'
|
|
|
|
re = %r{(?:/|^)#{re}[_.]}
|
2022-02-20 11:34:17 +00:00
|
|
|
|
2022-04-04 16:47:23 +00:00
|
|
|
self.reject! { |f| re.match f }
|
2017-04-02 19:56:30 +00:00
|
|
|
|
|
|
|
return self
|
|
|
|
end
|
2012-04-11 10:00:48 +00:00
|
|
|
end
|