I have this :
class Account
attr_reader :name
attr_reader :balance
def initialize (name, balance)
@name = name
@balance = balance
balance = 100
end
end
But when I run it I see this error message : **Oops, try again.**
Did you give your initialize method's balance parameter a default
value?
Can anyone explain to me what I did wrong ?
Roelof
On Mon, May 26, 2014 at 11:58 AM, Jesús Gabriel y Galán < jgabrielygalan@gmail.com> wrote:
On Mon, May 26, 2014 at 5:46 PM, Roelof Wobben <r.wobben@home.nl> wrote:
> Hello,
>
> I have this :
>
> class Account
> attr_reader :name
> attr_reader :balance
>
> def initialize (name, balance)
> @name = name
> @balance = balance
> balance = 100
> end
>
> end
>
> But when I run it I see this error message : Oops, try again. Did you
give
> your initialize method's balance parameter a default value?
>
> Can anyone explain to me what I did wrong ?
I have never seen the "Oops" message either. Maybe this what you are
looking for:
def initialize (name, balance=100)
···
On Mon, May 26, 2014 at 11:58 AM, Jesús Gabriel y Galán < jgabrielygalan@gmail.com> wrote:
On Mon, May 26, 2014 at 5:46 PM, Roelof Wobben <r.wobben@home.nl> wrote:
> Hello,
>
> I have this :
>
> class Account
> attr_reader :name
> attr_reader :balance
>
> def initialize (name, balance)
> @name = name
> @balance = balance
> balance = 100
> end
>
> end
>
> But when I run it I see this error message : Oops, try again. Did you
give
> your initialize method's balance parameter a default value?
>
> Can anyone explain to me what I did wrong ?
Thanks , too clarify. Im using
CodeAcademy to learn Ruby.
Another problem.
You can do this
x = y ? puts x : puts y
but what if you want to do multple things like this
x = y ? x -= 1; puts x : y-= 1 ; puts y
I see then a error message that the ; is found where a : is
expected
folding it into {} also do not seem to do the trick.
Roelof
Marian Mosley schreef op 26-5-2014 18:05:
···
I have never seen the "Oops" message either. Maybe
this what you are looking for:
def initialize (name, balance=100)
On Mon, May 26, 2014 at 11:58 AM, Jesús > Gabriel y Galán <jgabrielygalan@gmail.com> > wrote:
On Mon, May 26, 2014 at 5:46 PM, Roelof > > Wobben <r.wobben@home.nl > > > wrote:
> Hello,
>
> I have this :
>
> class Account
> attr_reader :name
> attr_reader :balance
>
> def initialize (name, balance)
> @name = name
> @balance = balance
> balance = 100
> end
>
> end
>
> But when I run it I see this error message : Oops,