Skip to content

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant