require ‘chronic’
puts "Enter the day of the week, and the date will be displayed "
inputday = gets.downcase.chomp!
User enters
monday
nextdate = Chronic.parse(‘next inputday’)
puts “The next”, inputday, "is "
puts nextdate
exit
I have tried every $, @ , @@ and single quotes and double quote
combinations I can think of. I can use the Time.now with offsets to get
the result I
need
But I am interested in having the ‘next inputday’ arguments evaluated
before Chronic uses them. I tried the eval command, but that did not
work.
Any ideas, thanks in advance.
Kindly
taz-uker
On Tue, Jul 26, 2011 at 5:53 PM, Terry Improv_coder [email protected]
wrote:
nextdate = Chronic.parse(‘next inputday’)
This sends it the exact string ‘next inputday’, when what you want to
do is make a string from 'next ’ + the contents of inputday. There are
several ways to do that:
String interpolation (requires double quotes)
nextdate = Chronic.parse(“next #{inputday}”)
String concatenation (single or double quotes)
nextdate = Chronic.parse('next ’ + inputday)
nextdate = Chronic.parse("next " + inputday)
etc.
I have tried every $, @ , @@ and single quotes and double quote
combinations I can think of.
It sounds like you need to review the differences between global ($),
instance (@), and class (@@) variables, on the one hand; and local
variables. inputday is a local variable, since it doesn’t start with a
distinguishing symbol; $inputday, @inputday, and @@inputday would all
be different.
Thanks, Eric
nextdate = Chronic.parse(“next #{inputday}”)
This worked. I am a newbie to Ruby, and I don’t know all the variable
syntax and relationships yet.
I appreciate it.
Terry
taz-uker.
Eric C. wrote in post #1013197:
On Tue, Jul 26, 2011 at 5:53 PM, Terry Improv_coder [email protected]
wrote:
nextdate = Chronic.parse(‘next inputday’)
This sends it the exact string ‘next inputday’, when what you want to
do is make a string from 'next ’ + the contents of inputday. There are
several ways to do that:
String interpolation (requires double quotes)
nextdate = Chronic.parse(“next #{inputday}”)
String concatenation (single or double quotes)
nextdate = Chronic.parse('next ’ + inputday)
nextdate = Chronic.parse("next " + inputday)
etc.
I have tried every $, @ , @@ and single quotes and double quote
combinations I can think of.
It sounds like you need to review the differences between global ($),
instance (@), and class (@@) variables, on the one hand; and local
variables. inputday is a local variable, since it doesn’t start with a
distinguishing symbol; $inputday, @inputday, and @@inputday would all
be different.