4

I'm learning Ruby and I'm trying to develop a blackjack game.

I create a class and here is the GIST

https://gist.github.com/robypez/7288032

my Hand class create a new hand object for a player (or for the dealer) It's an array, and inside the array every card is defined by an hash with this key :card, :suit, :value

I have a problem with the "compensate_ace_value" method. This method must use the "ace_number" value returned from the instance method ace_number

How can I call an instance method from another instance method inside a class?

I know that I can define an instance valuable that keep track of my ace number, but i want to know if is possible to call an instance method from another instance method inside a class.

My actual solution is to use the instance variable @ace_number and every time i call the method "receive_card" i call the method "is_ace?" on the card and in the result is true i increment the @ace_number variable.

Thank you

1 Answer 1

8

Here is some simple code to answer your subject question of the post.

How to call instance method from another instance method of the same class?

class Foo
  def bar
    11
  end

  def baz
    bar
  end
end

Foo.new.baz # => 11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.