How to convert string with point to symbol [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 7 years ago.
Improve this question
I am trying to convert the string "country." to a symbol. I expect to receive :country. including the point ..
I tried the following, but they do not work as my symbols still have quotes.
"country.".to_sym; #=> :"country."
"country.".intern; #=> :"country."
"country.".parameterize.underscore.to_sym; #=> :country
"country\.".to_sym; #=> :"country."

It's working as expected.
A symbol most of the time looks like:
:symbol_name
However when the symbol contains special characters such as spaces or hyphens, or in your case a period, it needs to be enclosed in quotes:
:"symbol name with-many special characters."
Although it doesn't look 'correct', it will act as any other symbol.

perhaps it will help you:
:'country.'

Related

Why is hello_world not working in Ruby on Ubuntu? [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 1 year ago.
Improve this question
My very first Ruby program: hello_world.rb:
puts ¨Hello World¨
I have saved it and when I try to run it from terminal, it returns:
ruby hello_world.rb
hello_world.rb:1:in `<main>': uninitialized constant World¨ (NameError)
I tried installing reinstalling ruby AND the editor(ATOM). That is really all I could think of to try. Any ideas would really help
-ruby 3.0.1p64. Ubuntu
Your string is not wrapped in double-quotes (") but in ¨ characters.
Replace
puts ¨Hello World¨
with
puts "Hello World"
You probably copy as pasted puts "Hello World" from some website whose formatting changes the quotes. They are not valid quotes for strings. Retype the quotes yourself.

Accented characters in Sphinx headings [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 1 year ago.
Improve this question
I want to include accented characters in a Sphinx heading such that I will see the following result:
Finalé
I have tried the following strategies:
Use the unicode character directly such as:
Finalé
======
but the character is considered invalid by Docutils.
Also, I have tried using the strip_html specification in conf.py along with the following text:
Finalé
==============
But the text is left unchanged and the HTML entity is passed through.
Can anyone suggest a way of handling accented characters in Sphinx that will work in all situations and where the final output may be HTML or Latex?

ISO String to Datetime in ruby invalid date? [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 5 years ago.
Improve this question
I am trying to convert a string to a date time object. The string looks like this
"2016-06-16T23:26:25.252Z"
I have been trying to convert it using DateTime.strptime(str,"'%Y-%m-%dT%H:%M:%S.%L%z") but gives invalid date error.
Do any of you know the issue?
Thanks!
You put an extra quotation mark in the string.
str = "2016-06-16T23:26:25.252Z"
DateTime.strptime(str,"'%Y-%m-%dT%H:%M:%S.%L%z") #=> ArgumentError: invalid date
DateTime.strptime(str,"%Y-%m-%dT%H:%M:%S.%L%z") #=> #<DateTime: 2016-06-16T23:26:25+00:00 ((2457556j,84385s,252000000n),+0s,2299161j)>
^^^

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})

Passing arguments to methods [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 8 years ago.
Improve this question
I have a method gcd that takes two arguments. When I do this:
gcd (20,40)
I get this error
syntax error, unexpected ',', expecting ')'
Removing the parentheses fixes the problem, but is there some way to use parentheses and still get this code to work?
There are two ways to pass arguments to a method:
in parentheses directly after the method name
without parentheses with whitespace after the method name
You have white space after the method, ergo you are using option #2 and are passing a single argument (20, 40) to the method, but (20, 40) is not legal syntax.
You shouldn't put space between method and arguments. It should be:
gcd(20, 40)

Resources