Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have this code:
Class Card
def initialize(suit, number)
#suit = suit
#number = number
end
end
I am getting the error message:
/go_fish/lib/Card.rb:8 syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
Any suggestions or stuff I'm missing?
Your error is the first char in the first line. class should be lowercase...
class Card
def initialize(suit, number)
#suit = suit
#number = number
end
end
Furthermore you may want to follow common rules for coding styles in Ruby. To do so change the file name to card.rb (again lowercase), same with require. And it is common to indent with just two whitespace characters in Ruby files.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
What is the syntax error in this short ruby block?
def do_this (a,b,c)
puts 1.to_s, 2.to_s,3.to_s
if a == 4
do_this (1,2,3)
end
end
do_this (4,5,6)
I get errors on the fourth and seventh lines, where "do_this" is called.
The error is: 'unexpected ")", expecting "." or...' [...]
Remove spaces between method name and parentheses.
You need to avoid using spaces between the method call and the arguments in parenthesis:
def do_this (a,b,c)
puts 1.to_s, 2.to_s,3.to_s
if a == 4
do_this(1,2,3)
end
end
do_this(4,5,6)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've got a problem in Ruby, "unexpected tidentifier expecting keyword_end", how Can I solve it?
def riko(user)
if user.name.eql? 'Mia Khalifa Fan'
#client.send_msg 'Hola Mia <3 ¿Cómo te trato este dia, cosa guapa y sensual?',
else
if user.mame.eql? 'Skul Goy'
#client.send_msg 'Muerete. '
else
#client.send_msg "Hola #{user.name} o/ \ :v / "
end
end
You're using else if which works fine in other languages, but in Ruby represents 2 distinct conditionals. You probably want to replace it with elsif instead, which is the Ruby equivalent.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Tried to include a module in another one, but something goes wrong
ruby pipboy.rb
pipboy.rb:3: syntax error, unexpected '<', expecting ';' or '\n'
def Pipboy < Person
^
pipboy.rb:22: syntax error, unexpected keyword_end, expecting end-of-input
def is a keyword to define methods. You probably want to derive a class/module. This is to be done with:
class Pipboy < Person
to include (as stated in OP) one module into other, one should use include keyword:
class Pipboy
include Person
...
The def keyword is used to create function definitions. What you are thinking of is the class keyword.
Make sure you have a Pipboy class, and then do class Pipboy < Person
Here is more information on inheritance
http://rubylearning.com/satishtalim/ruby_inheritance.html
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am building a rather simple Module::Class with a initialize method.
module Encryption
class Caesar
def initalize(number)
#caesar_number = number
end
end
end
when I run Encryption::Caesar.new(2) i get the following error:
ArgumentError: wrong number of arguments (1 for 0)
from (irb):32:in `initialize'
from (irb):32:in `new'
from (irb):32
from /Users/yedidyaweiner/.rvm/rubies/ruby-2.1.3/bin/irb:11:in `<main>
If i run Encryption::Caesar.new, it successfully creates a new instance of the class.
Why is the error saying that it does not expect an argument when it is defined in the initialize method?
initalize is misspelled; it should be initialize.
module Encryption
class Caesar
def initialize(number)
#caesar_number = number
end
end
end
foo = Encryption::Caesar.new(2)
foo.inspect #=> #<Encryption::Caesar:0x1e05580 #caesar_number=2>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have code like the following:
arra = ["a","b","c"]
arrb = ["a","e","d"]
arrc = arra - arrb
while arrc.size != 0
somedef(arrc)
end
I get this error:
NameError: undefined local variable or method `arrc' for main:Object
pointing to the line inside the while loop. Can anyone help me understand why this is?
Are you doing something like this in "somedef":
def somedef(a)
p arrc
end
If so, you get the error because "arrc" is not a global variable. Do this instead:
def somedef(a)
p a
end