When `.from_hash` argument has a key with `-`, an error occurs
tsub opened this issue · 3 comments
tsub commented
I have issues
When .from_hash
argument has a key with -
, an error occurs.
$ bundle exec irb
irb(main):001:0> require 'type_struct'
=> true
irb(main):002:0> Type = TypeStruct.new('hoge-id': String)
=> Type
irb(main):003:0> Type.from_hash('hoge-id': '123456')
Traceback (most recent call last):
16: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
15: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
14: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:465:in `exec'
13: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:28:in `run'
12: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
11: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `load'
10: from /Users/tsub/.asdf/installs/ruby/2.6.3/bin/irb:23:in `<top (required)>'
9: from /Users/tsub/.asdf/installs/ruby/2.6.3/bin/irb:23:in `load'
8: from /Users/tsub/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
7: from (irb):3
6: from /Users/tsub/sandbox/reproduce_typestruct_error/vendor/bundle/gems/type_struct-0.7.4/lib/type_struct.rb:77:in `from_hash'
5: from /Users/tsub/sandbox/reproduce_typestruct_error/vendor/bundle/gems/type_struct-0.7.4/lib/type_struct.rb:77:in `new'
4: from /Users/tsub/sandbox/reproduce_typestruct_error/vendor/bundle/gems/type_struct-0.7.4/lib/type_struct.rb:21:in `initialize'
3: from /Users/tsub/sandbox/reproduce_typestruct_error/vendor/bundle/gems/type_struct-0.7.4/lib/type_struct.rb:21:in `each'
2: from /Users/tsub/sandbox/reproduce_typestruct_error/vendor/bundle/gems/type_struct-0.7.4/lib/type_struct.rb:29:in `block in initialize'
1: from /Users/tsub/sandbox/reproduce_typestruct_error/vendor/bundle/gems/type_struct-0.7.4/lib/type_struct.rb:29:in `instance_variable_set'
NameError (`@hoge-id' is not allowed as an instance variable name)
NameError (@hoge-id' is not allowed as an instance variable name)
is raised.
By the way, as an example of Hash key containing -
, AWS Lambda event.
Environment details
- Ruby: 2.6.3
- type_struct: 0.7.4
ksss commented
Thank you for reporting!
I'll fix it later.
tsub commented
I was able to confirm that it came to work as intended.
$ bundle update type_struct
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 2.0.2
Fetching type_struct 0.8.0 (was 0.7.4)
Installing type_struct 0.8.0 (was 0.7.4)
Bundle updated!
$ bundle exec irb
irb(main):001:0> require 'type_struct'
=> true
irb(main):002:0> Type = TypeStruct.new('hoge-id': String)
=> Type
irb(main):003:0> Type.from_hash('hoge-id': '123456')
=> #<Type hoge-id="123456">
irb(main):004:0> Type.from_hash('hoge-id': '123456')['hoge-id']
=> "123456"
@ksss Many thanks!