Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'pry'
- class Phone
- def initialize(number)
- @trim = number.gsub(/[^0-9]/, '')
- end
- def number
- if @trim.length == 11 && @trim.chars.first == '1'
- @trim.slice(1..@trim.length)
- elsif @trim.length != 10
- @trim = "0000000000"
- else
- @trim
- end
- end
- def area_code
- @trim.slice(0..2)
- end
- def to_s
- first = @trim.slice(0..2)
- second = @trim.slice(3..5)
- third = @trim.slice(6..9)
- return "(#{first}) #{second}-#{third}"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement