makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Support attributes that are also a keyword #165

Closed tom-kuca closed 2 years ago

tom-kuca commented 2 years ago

Fix an error when an attribute name is a keyword, e.g. alias, end, …

Given

attribute :alias, :string

I got an error

SyntaxError:
  active_type-2.2.0/lib/active_type/virtual_attributes.rb:103: syntax error, unexpected '[', expecting `end'
  ...ias != virtual_attributes_were["alias"]

The patch adds a prefix self that fixes the syntax error in generated code.

self.alias != virtual_attributes_were["alias"]
kratob commented 2 years ago

Sorry for the slow response, thanks for the PR!