Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

#to_hash and implicit conversion #584

Description

@antstorm

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?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions