Created
January 13, 2013 23:51
-
-
Save sxross/4526905 to your computer and use it in GitHub Desktop.
RubyMotion Extension I Can't Get To Work
This file contains 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 String | |
def add_formatted(str, format = '%s') | |
return self if str.nil? | |
self << format % str if str.length > 0 | |
self | |
end | |
def to_us_phone | |
phone = self.dup.gsub(/[^\d]/, '') | |
last = phone[-4..-1] | |
pre = phone[-7..-5] | |
area = phone[-10..-8] | |
rest = phone[-(phone.length)..-11] | |
String.new.add_formatted(rest, "+%s "). | |
add_formatted(area, "(%s) "). | |
add_formatted(pre, "%s-"). | |
add_formatted(last) | |
end | |
end | |
class Fixnum | |
def to_us_phone | |
self.to_s.to_us_phone | |
end | |
def to_countable_s(thing, if_zero = 'no') | |
number = self == 0 ? if_zero : self.to_s | |
return number if self == 0 | |
thang = self == 1 ? thing : thing.pluralize | |
"#{number} #{thang}" | |
end | |
end | |
class Bignum | |
def to_us_phone | |
self.to_s.to_us_phone | |
end | |
def to_countable_s(thing, if_zero = 'no') | |
number = self == 0 ? if_zero : self.to_s | |
return number if self == 0 | |
thang = self == 1 ? thing : thing.pluralize | |
"#{number} #{thang}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment