syntax error, unexpected tINTEGER, expecting '(' [closed] - ruby-on-rails

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
My code is
for i in 0..array_dif.count-1
a = array_dif[i] - array_dif[0]
b = array_dif[array_dif.count-1] - array_dif[0]
norm = a.0/b
array_norm[i] = norm
end
And i'm getting the following error:
rb:135: no .<digit> floating literal anymore; put 0 before dot (SyntaxError)
norm = a.0/b
^
C:/piegas/config/initializers/backtrace_silencers.rb:135: syntax error, unexpected tINTEGER, expecting '('
norm = a.0/b
^
I don't know whats wrong with it

norm = a.0/b is an invalid statement (aka SyntaxError).
What do you want that statement to do?
norm = a/b might make sense.
norm = array_dif[0]/b might also make sense.
But without knowing the purpose of the code, it's difficult to know what the correct solution is.

What do you mean by a.0/b? It is invalid. If you were trying to convert a to float then it would be a.to_f/b.

Related

Swift 'fabs' is deprecated: renamed to 'abs' [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
When I try using fabs on a CGFloat number in Swift 5, I get this warning:
'fabs' is deprecated: renamed to 'abs'
But when I use abs, it's argument is only Integer, not Float or Double. I am using XCode 12 if that matters. How do I resolve this?
You're probably using abs from the Foundation framework.
Try the following:
Swift.abs(CGFloat(1.0))
Foundation.abs(CGFloat(1.0)) // Cannot convert value of type 'CGFloat' to expected argument type 'Int32'
Swift.abs(CGFloat(1.0)) // Compiles successfully
Just use CGFloat.magnitude
CGFloat(-1.23).magnitude // => 1.23

How to find total amount from a string using regex [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 4 years ago.
Improve this question
Hi i am working on a ruby on rails project wih ruby-2.5.0 and rails 5. I have a string which contains the total amount. So i need to find the total amount using regex.
String:-
"TOTAL
EFT
CHANGE
Taxable Ite.s
TOTAL includes GST
OTHER SAVINGS
0000000000
$73.26
HAIERF(RDS stm IGA
KARAWARA *AOI
TERMINAL"
Here $73.26 is the total amount. I tried /$(\d{1,2}(\.)\d{1,2})/ and /^\d{1,4}(\.\d{0,2})?$/ But its not working. Please help me with exact regex. Thanks in advance.
Updated As per the op's comment:
/TOTAL(?=((?!TOTAL).)*).*?(\$\d{1,4}(?:\.\d{1,2})?)/im
This is a compilation of both of your regex.
Regex Demo
Sample Source ( Run Here )
re = /TOTAL(?=((?!TOTAL).)*).*?(\$\d{1,4}(?:\.\d{1,2})?)/im
str = 'TOTAL $234
EFT
CHANGE
Taxable Ite.s
TOTAL includes GST
OTHER SAVINGS
0000000000
$73.26
HAIERF(RDS stm IGA
KARAWARA *AOI
TERMINAL
$83.26
Total
asdasfd
sadfasdf
$1235
'
str.scan(re) do |match|
puts match[1]
end

Neo4jClient: Wild char Search do not work when parametarized [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 having a strange issue with the Neo4JClient.
The following query works
.AndWhere("((shipper.Name =~ '(?i).*" + filterTxt + ".*') OR (frm.Name =~ '(?i).*" + filterTxt + ".*') OR (to.Name =~ '(?i).*" + filterTxt + ".*'))");
but the same when I convert to the parameterized query like below:
.AndWhere("((shipper.Name =~ {searchParam}) OR (frm.Name =~ {searchParam}) OR (to.Name =~ {searchParam}))")
.WithParam("searchParam", "(?i).*" + filterTxt + ".*");
it fails to execute from within the Neo4JClient I get an exception saying connection is closed, however when I pickup the DebugQueryText generated by the Neo4JClient, and execute it on the neo4j console, it returns result.
is there something I am doing wrong with the way I am using this wildcard search?
Regrads
Kiran

Get the sub string between two bracket in ruby on rails [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
I have following strings:
1) Beach Cottage (CP)
2) Beach Cottage (AP)
3) Cotta (GAP)
And I want to get substing between ( ) that is from first CP
Try this for example:
str = "Beach Cottage (CP)"
str.match(/(\((.*)\))/)[2]
you can use scan also with regx:
str = "Beach Cottage (CP)"
needed_sub_str = str.scan(/\((.*)\)/)
puts "expected sub string :: #{needed_sub_str}"
Output ::
expected sub string :: CP

Ruby/Rails hash rockets Syntax [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Can someone point me to a good primer just explaining the different syntactic features in Ruby/Rails? For instance, how come some examples I see do myMethod(x: "z") and others do myMethod(:x => "x")?
The syntax in general seems strange to me, just looking for a quick at-a-glance reference to use as a cheat sheet.
They are the same, it is just a matter of preferences.
I also asked myself why would we add this new syntax if we already have one? Well, Programming with Ruby implies that we are lazy and want to type the less possible caracters. So this new syntax allow us - lazy programmers - to write the same thing, minus 1 caracter!
But keep in mind some stuff, like the type of the keys for instance (Ruby 1.9.3):
> {a: 12}.class
=> Hash
> {:a => 12}.class
=> Hash
> {'a' => 12}.keys.first.class
=> String
> {a: 12}.keys.first.class
=> Symbol
Also, some declaration are illegal with the new syntax:
> { '1-2' => "something" }
=> {"1-2"=>"something"}
> { 1-2: "something" }
SyntaxError: (irb):38: syntax error, unexpected ':', expecting tASSOC
{ 1-2: "something" }
^
(irb):38: syntax error, unexpected '}', expecting $end
For more informations: Is there any difference between the `:key => "value"` and `key: "value"` hash notations?

Resources