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

#to_hash and implicit conversion #584

Open
antstorm opened this issue Sep 23, 2020 · 4 comments
Open

#to_hash and implicit conversion #584

antstorm opened this issue Sep 23, 2020 · 4 comments

Comments

@antstorm
Copy link

Something that caught me off guard when using an instance of Hanami::Entity with Ruby's double splat:

class User < Hanami::Entity
  attributes do
    attribute :id,   Types::Int
    attribute :name, Types::String
  end
end

def test_me(user = nil, **options)
  puts "user: #{user}"
  puts "options: #{options}"
end

> test_me(User.new(id: 42, name: 'Tester'))
user:
options: {:id=>:42,:name=>'Tester'}

Due to implicit conversion (#to_hash) User instance gets deconstructed into a hash when passed into the test method. The behaviour was introduce in this PR — 26c17eb.

My question is — was it intentional and there's a legit use-case or accidental?

@solnic
Copy link
Member

solnic commented Sep 24, 2020

This will be addressed in Hanami 2.0. This method will be gone as it has confusing behaviors like you noticed.

@antstorm
Copy link
Author

This is great, thank you, @solnic!

Do you have a timeline in mind for Hanami 2.0? I know things have been a bit stale recently

@solnic
Copy link
Member

solnic commented Sep 25, 2020

@antstorm we'll be posting an official roadmap/timeline very soon! I recommend following Tim's updates on his blog too. You can also see our Trello board to get a sense of where we are in the process.

@antstorm
Copy link
Author

@solnic ah, lovely, great to see there's some progress on the project. I really enjoy Hanami and have been running it in production for 1.5 years now

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

No branches or pull requests

2 participants