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

Add URI::Generic#deconstruct and URI::Generic#deconstruct_keys #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

miyucy
Copy link

@miyucy miyucy commented Feb 21, 2023

I added the following method because there are times when I want to right-assign the components of a URI object or use pattern matching while writing an application.

irb(main):003:0> u = URI("http://example.com")
=> #<URI::HTTP http://example.com>
irb(main):004:0> u => { host: }
(irb):4:in `<main>': #<URI::HTTP http://example.com>: #<URI::HTTP http://example.com> does not respond to #deconstruct_keys (NoMatchingPatternError)
        from ~/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from ~/.rbenv/versions/3.2.1/bin/irb:25:in `load'
        from ~/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'

irb(main):002:0> u = URI("http://example.com")
=> #<URI::HTTP http://example.com>
irb(main):003:1* case u
irb(main):004:1* in host: /foo.com/
irb(main):005:1*   puts "OK"
irb(main):006:1* else
irb(main):007:1*   puts "NG"
irb(main):008:0> end
NG
=> nil

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

Successfully merging this pull request may close these issues.

1 participant