Skip to content

Instantly share code, notes, and snippets.

@sumdog
Created June 29, 2017 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumdog/e4b556af98a8ce0f902b6a158b60159a to your computer and use it in GitHub Desktop.
Save sumdog/e4b556af98a8ce0f902b6a158b60159a to your computer and use it in GitHub Desktop.
# 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