Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named tuple string key access #3143

Merged
merged 4 commits into from
Aug 18, 2016

Conversation

jhass
Copy link
Member

@jhass jhass commented Aug 12, 2016

Implements #2966

@jhass jhass force-pushed the named_tuple_string_keys branch from 0e1a2f6 to 58a16c3 Compare August 12, 2016 10:36
@asterite
Copy link
Member

I'm almost 👍 on this, I need to check with @waj. I'd also need to add a rule to the compiler to simplify named tuple indexing with string literals, like it's done now with symbol literals (a very easy change)

t["foo"]?
)) { nil_type }
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's the right place for these specs, but couldn't find anything else.

@jhass jhass force-pushed the named_tuple_string_keys branch 3 times, most recently from 6bca933 to af48e1b Compare August 12, 2016 15:02
@jhass jhass force-pushed the named_tuple_string_keys branch from af48e1b to 88fdd4f Compare August 12, 2016 15:54
# ```
def gsub(tuple : NamedTuple)
gsub do |char|
tuple[char.to_s]? || char
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we haveTuple#fetch to allow proper non-fallbacking when the actual value is falsy?
Not particularly needed in this case, but It's been a week with hash[key] || default bugs on my side :-)

Maybe adding Indexable#fetch?
Hash#fetch currently uses #find_entry, so I don't expect to promote that method to the module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I change something here or do you consider it a separate change? (I think I do personally). Note that the same pattern is currently in use for the existing Hash(Char, _) overload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's do it in a separate commit and get this merged. Apologies for the delay @jhass

@asterite
Copy link
Member

@jhass Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants