KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Let's take this example: d = {"a" => 1, "b" => 2, "c" => 3, "d" => 4} Since hashes are now ordered, I might want to get data from a to b or from c to d . The problem is that I can't do d[0..1] or d[2..3] . I could however do: irb > d.to_a[0..1] => [["a", 1], ["b", 2]] ... but this feels messy and I don't want to cast my hash for an operation like this. Is there a cleaner solution to handle this? # Holy Grail irb > d[0..1] => {"a" => 1, "b" => 2} I can see how to program myself such a method, but there might be something native already done that I could use...?
Tags (comma-separated)
Save Edits
Cancel