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 have:
str = "something"
str[0, 1] #=> "s"
str[0, 2] #=> "so"
str[3, 4] #=> "ethi"
str[2, 3] #=> "meth"
I can't see logic in this. What is returned by this double indexes?
str[2,3] is "met". In this form it is str[zero_based_start_position, number_of_characters]
See ruby documentation on String class
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 4 years ago.
Improve this question
class Song
def initilaize(name,artist,duration)
#name=name
#artist=artist
#duration=duration
end
end
song = Song.new("ruby","Bicylops " ,260)
puts song.artist
Very simple.
You spelled initialize as initilaize.
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
I have tried the following:
iconv('ISO-8859-1', 'UTF-8//IGNORE', 'BIG5', $input);
However, it fails and produces this error:
iconv() expects exactly 3 parameters, 4 given
Check the official documentation:
http://php.net/manual/en/function.iconv.php
You're passing an extra argument to the function.
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
myhash = {answer: "yes", something: hello, another: "yes"}
myhash.delete[another]
I want to delete the another key-value pair. But, ruby gives me an error saying wrong number of arguments (0 for 1). What's going on?
the method delete is a method, not an element on the hash , and another key is a symbol, so you should call on this form
myhash.delete(:another)
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'm trying to find the greatest prime number based on a max value...I just want this to print the largest prime number but I can't figure out how to break this loop after printing the first number.
require 'prime'
1000.downto(1) do |i|
while i.prime? do print i
end
end
i am not familiar with ruby but i guess it should work
1000.downto(1) do |i|
if i.prime? then
print i
break
end
end
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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
Improve this question
In irb
[[]] | [3]
produces
[[], 3]
I am having some difficulty understanding it. How is the OR operator working here ?
According to the documentation,
Set Union — Returns a new array by joining ary with other_ary,
excluding any duplicates and preserving the order from the original
array.
[1,2,3] | [4,5,6] # => [1, 2, 3, 4, 5, 6]
[1,2,3] | [4,1,2] # => [1, 2, 3, 4]
|| is the logical OR operator you might be thinking of.
| with arrays performs a set union operation on the arrays and gives you an array that has all the unique elements of both arrays. More details at ruby-doc