Skip to content

JRuby 9.0.1.0 vs. MRI 2.2.2 define_method inconsistency #3326

@PetrKaleta

Description

@PetrKaleta

Hey, after upgrading from JRuby 1.7.22 to JRuby 9.0.1.0 I found, that warden is raising errors when logging user in. So I was digging a little bit and found, that there's inconsistency in behaviour between ruby versions.

Let me describe it on the following code (working subset from warden gem):

class SessionSerializer
  def serialize(obj)
    obj
  end
end

class Manager
  def self.serialize_into_session(&block)
    SessionSerializer.send :define_method, :serialize, &block
  end
end

And now how it behaves on JRuby 1.7.22 and MRI 2.2.2

Manager.serialize_into_session { |obj| obj.to_s } # => :serialize
SessionSerializer.new.serialize(1) # => 1
Manager.serialize_into_session(&:to_s) # => :serialize
SessionSerializer.new.serialize(1) # => 1

So the result is as expected, but now what about JRuby 9.0.1.0:

Manager.serialize_into_session { |obj| obj.to_s } # => :serialize
SessionSerializer.new.serialize(1) # => 1
Manager.serialize_into_session(&:to_s) # => :serialize
SessionSerializer.new.serialize(1) # ArgumentError: wrong number of arguments (1 for 0)

Hope this helps to identify this define_method inconsistency.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions