Created
June 29, 2017 02:21
-
-
Save sumdog/e4b556af98a8ce0f902b6a158b60159a to your computer and use it in GitHub Desktop.
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
# Records = [ 'something.example.com', 'some.other.example.com', 'example.net', 'somethingelse.example.net', 'example.org' ] | |
def domain_records(records) | |
records.map { |r| | |
base = r.split('.')[1..2].join('.') | |
sub_domain = .split('.')[-3].join('.') | |
} | |
end | |
# Is there a functional way to get a result like.. | |
# { 'example.com' => [ 'something', 'some.other' ], 'example.net' => ['somethingelse'], 'example.org' => [] } | |
# | |
# I realize I can create a hash and do an .each to insert records into the map, but is there a way to do this | |
# without mutable elements using something like .collect? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment