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 5 years ago.
Improve this question
I'm trying to use a negative value in a string which is in a hash.
{"amount"=>"-50.01", "currency"=>"CAD"}
If I write transaction.amount I get 0.5001E2, if I use to_f I get 50.01.
I'm trying to extract the -50 value.
Thank you for your help!
Try
transaction['amount']
For example
a = {"amount"=>"-50.01", "currency"=>"CAD"}
Then
a['amount']
returns '-50.01'
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a hash like the one shown below
profile={"acakxqcnwbhtfcppyilk"=>"unlocked", "achurktnaavqqnwtfvvt"=>"locked", "chrofmjydwzcbswhpste"=>"locked", "ChromeProfile"=>"unlocked", "clcqozsfdblntkwlcheo"=>"unlocked", "gpqhioztlmkoitjqxerm"=>"unlocked", "hododpaxflyzgpwortjl"=>"unlocked", "hyqnjrpttwclueqwttdw"=>"unlocked", "jtdeyzcxdpgblxmpldtx"=>"unlocked", "kifxvxmbifkicmapedir"=>"unlocked", "lucjkeeqzynhjurnpewl"=>"unlocked", "lyccchkgyscmljcvkvcj"=>"unlocked", "nmqhlowcqnwmwbxijwry"=>"unlocked", "nseucpicwbcyviargwjt"=>"unlocked", "osecuzrbvodwgkdwovjd"=>"unlocked", "pqhlxugxqppfybxdkemr"=>"unlocked", "qgoaryzyriohpwzbprgg"=>"unlocked", "rwtlttvtbrmziyuimgad"=>"unlocked", "sxkcvnlsgqauwcbkmjcy"=>"unlocked", "uyfvlzyllwimhklmmmns"=>"unlocked", "vgvobxhpflhappnajizs"=>"unlocked", "vlbbphwoyweyguhcmdwv"=>"unlocked", "vrsjncafxunswclescvu"=>"unlocked", "wxsninefjvtrxvntgkni"=>"unlocked", "xdqndtyyxctkovyfsldi"=>"unlocked", "ycvguesevlbopicmxfbc"=>"unlocked"}
I have to return the key which has the value 'locked', If there are more than one 'locked' is present, then the first one has to be returned.
Is there any specific method is available to accomplish task?
Try the key() method
profile.key('locked')
Read more here
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
I'm working with a script that only takes integer values. I'm reading from a CSV with a timestamp example of 12:34. Is there a way I get ruby to read it as an integer?
Not sure if you are dealing with a Time object. If so:
str = Time.now.to_s[/\d\d:\d\d:\d\d/]
=> "19:04:53"
str.gsub(":", "").to_i
=> 190453
If it's a string just start with the sub:
"12:34".sub(":", "").to_i
=> 1234
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 8 years ago.
Improve this question
How to min inside the formula to evaluate using eval().
[5,6].min works fine but it doesn't work inside the formula eval([5,6].min*5).
Here is a way using #eval. But why you need #eval ?
eval('[5,6].min * 5')
# => 25
Simply [5,6].min * 5 will work for you.
You don't need eval.
[5,6].min*5.
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 8 years ago.
Improve this question
I have an api, which has java DateTime type, which returns the following hash:
{"Date":1403592945000}
The actual date value is: "2014-06-24 06:55:45". How do I convert it in Ruby?
Time.at is the function you want to use. However, it seems that your value also contains milliseconds, that in Ruby should passed apart.
Time.at(1403592945000) # wrong
Time.at(1403592945) # => 2014-06-24 08:55:45 +0200
This will work:
Time.at(hash['Date']/1000)
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 9 years ago.
Improve this question
Is it possible to pass parameter to a method like this:
variable = my_method(:parameter)
No quotes, no nothing.Just -> :parameter .
Yes, you can pass a symbol to a method. Example:
puts('hello')
or
puts(:hello)