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

Assigning attributes can nil them out #47

Closed
tfausak opened this issue Aug 16, 2013 · 5 comments
Closed

Assigning attributes can nil them out #47

tfausak opened this issue Aug 16, 2013 · 5 comments
Assignees
Labels

Comments

@tfausak
Copy link
Collaborator

tfausak commented Aug 16, 2013

This is distressing, to say the least:

class Interaction < ActiveInteraction::Base
  boolean :a
  def execute; a = a end
end
p Interaction.run!(a: true)
# => nil
@tfausak
Copy link
Collaborator Author

tfausak commented Aug 16, 2013

Only happens the first time:

class Interaction < ActiveInteraction::Base
  boolean :a
  def execute
    a = false
    a = a
  end
end
p Interaction.run!(a: true)
# => false

@tfausak
Copy link
Collaborator Author

tfausak commented Aug 16, 2013

Getting more confused:

class Interaction < ActiveInteraction::Base
  boolean :a
  def execute
    b = a
    a = b
  end
end
p Interaction.run!(a: true)
# => true

@tfausak
Copy link
Collaborator Author

tfausak commented Aug 16, 2013

Adding self. makes it work:

class Interaction < ActiveInteraction::Base
  boolean :a
  def execute; a = self.a end
end
p Interaction.run!(a: true)
# => true

@tfausak
Copy link
Collaborator Author

tfausak commented Aug 16, 2013

Turns out this is not a bug against ActiveInteraction — it's just weird Ruby behavior!

class Klass
  def initialize;   @thing = 'swamp' end
  def thing;        @thing end
  def thing=(other) @thing = other end
  def test1;        thing = thing end
  def test2;        self.thing = thing end
  def test3;        thing = self.thing end
end
klass = Klass.new
p klass.test1 # => nil
p klass.test2 # => "swamp"
p klass.test3 # => "swamp"

@tfausak tfausak closed this as completed Aug 16, 2013
@ghost ghost assigned tfausak Aug 16, 2013
@tfausak
Copy link
Collaborator Author

tfausak commented Aug 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant