What does `s.?('').?.?` mean? [closed] - ruby

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'm following the ruby on rails guide written by Micheal Harl. I"m wondering what ?('').?.? means in the code below.
def string_shuffle(s)
s.?('').?.?
end
string_shuffle("foobar")
# => "oobfra"

I think it should be replaced with methods, like bellow:
def string_shuffle(s)
s.split('').shuffle.join
end
def string_shuffle(s)
s.split('').shuffle.join
end
string_shuffle("foobar")
# => "oafrob"

It doesn't mean anything. It's a syntax error. That code is not legal Ruby.

Related

Method cannot be called inside of a class [closed]

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 3 years ago.
Improve this question
This program runs as intended if outside a class, how could this be run inside of one?
class Pointester
$points = 0
def point_tracker()
puts $points
end
point_tracker()
end
Here's the error: undefined method `point_tracker' for Pointester:Class (NoMethodError)
Change it to:
class Pointester
$points = 0
def point_tracker
puts $points
end
end
Pointester.new.point_tracker
And you might want to consider using an instance instead of a global variable – depending on your use-case.

Check if Hash is included in output [closed]

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 am trying to check if a specific element is included in an output. I run:
results.include? {"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100}
but I get an error:
Syntax error, unexpected =>, expecting '}'
What did I do wrong?
The problem is that the curly brackets in this case are interpreted as start of a block. Just put () around:
results.include?({"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100})

Trying to access array within a hash in ruby [closed]

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 trying to parse a hash in ruby. I have an array an array of 'entries'. I want to take each entity and get array of runs within it (I want to store the runs in a different variable as seen below). My problem is that runs always turns out nil. Below is my code:
entries = test_plan['entries']
entries.each do |ent|
puts "in entries"
puts ent
runs = ent['runs]']
runs.each do |run|
and what an 'entries' hash looks like.
{"id"=>"7", "suite_id"=>729, "name"=>"Regression", "runs"=>[{"id"=>2588, "suite_id"=>729}]}
There is a simple typo. Change
runs = ent['runs]']
to
runs = ent['runs']

Why can interactive Ruby run a program, but sublime editor not? [closed]

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 wrote code like this:
class Animal
attr_accessor :name, :color, :age
end
first_animal = animal.new
first_animal.name = "Floyd"
first_animal.color = "white"
first_animal.age = 7
puts first_animal.name
When I save it and drag onto "command prompt with Ruby" and press enter, it says undefined local variable, but when I write the code using interactive ruby (IRB terminal) it works fine. It shows me the results of first_animal.name etc. Where is the problem?
You have syntax mistake:
Animal.new instead of animal.new

Ruby function titled inflect [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Here is ruby code:
[:val1, :val2, :val3].each do |method_name|
define_method(met_n) do |param1, param2|
inflect(param1, param2, SOME_CONST[met_n.to_s])
end
end
It's not mine code. I tried to figure out what inflect is, but I failed, although it should be a standard ruby function.
So how is it defined or where do I find a documentation about it?
inflect isn't a standard ruby function. This must be part of someone else's API.

Resources