Last active
September 16, 2016 18:46
-
-
Save thescubageek/d67be752dbd6856b445327f0be45c771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def to_file(filepath, sep="\n") | |
File.open(filepath, 'w') { |f| f.write(join(sep)) } unless blank? | |
end | |
def squash | |
blank? ? [] : flatten.compact.uniq | |
end | |
end | |
class File | |
def self.to_a(filepath, sep="\n") | |
open(filepath).to_a(sep) if exists?(filepath) | |
end | |
def to_a(sep="\n") | |
read.each_line.inject([]) do |arr, line| | |
arr << line.strip unless line == sep | |
arr | |
end | |
end | |
end | |
class String | |
def to_boolean | |
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(self) | |
end | |
end | |
class NilClass | |
def to_boolean | |
false | |
end | |
def squash | |
[] | |
end | |
end | |
class TrueClass | |
def to_boolean | |
true | |
end | |
end | |
class FalseClass | |
def to_boolean | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment