Skip to content

Instantly share code, notes, and snippets.

@thescubageek
Last active September 16, 2016 18:46
Show Gist options
  • Save thescubageek/d67be752dbd6856b445327f0be45c771 to your computer and use it in GitHub Desktop.
Save thescubageek/d67be752dbd6856b445327f0be45c771 to your computer and use it in GitHub Desktop.
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