Why does Eclipse complain about "Feature envy" smell in my code? [closed] - ruby

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 7 years ago.
Improve this question
Eclipse (RedRails) complain about "Feature envy" in the following code:
if input_text =~ /^(---\s*\n.*?\n?)(---.*?)/m
content_text = input_text[($1.size + $2.size)..-1] # warning in $1
header = YAML.load($1)
#content = content_text.strip()
#title = header["title"]
end
My understanding is that I safe to ignore this warning. But I am wandering why this warning is generated. I cannot understand how I can extract method for $1.size and $1.

Reek is telling you that, because you are adding two properties of the same class, the calculation should actually belong in String. When adding string lengths this is nonsense of course, but in your case the code can be simplified by using $& (the complete matched string):
input_text[$&.size..-1]

Related

When applying the annotation, it throws an error (#SpringBootApplication) [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 5 months ago.
Improve this question
such a question. When adding the annotation #SpringBootApplication(exclude={SecurityAutoConfiguration.class}) Gives an error when building Name expected The IDE writes like this:
enter image description here
What could be the problem?
Assuming by tags that you are using kotlin and it has slightly different syntax actually.
Change
#SpringBootApplication(exclude={SecurityAutoConfiguration.class})
To
#SpringBootApplication(exclude=[SecurityAutoConfiguration::class])

How do I use include method with the whole alphabet? [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 8 years ago.
Improve this question
I want to know if a string includes the form '+#someletter#+', where #someletter# is a
letter. If the string is 'dogs+d+', it would be true because it contains '+d+'. If the string is 'dogs++c', it would be false because the 'c' wasn't surrounded by '+' signs.
I was thinking it was something using regexp like
string.include? '+/a-z/+'
but that doesn't work. Please help.
include? does not accept a regex. To use a regex, you need a different method.
string =~ /\+[a-z]\+/

Bug in Ruby RPG (skips line in case..when) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am currently developing a text-based RPG in Ruby, however there are some bugs in the programming code. The code is long, so I'll provide a link to the Source Code HERE.
The problem occurs at line 113. Whenever I enter "y" for case randEvent1 it accepts it and does the following lines in the when statement but when I put in "yes", it skips all of those lines goes to the line:
puts "Do you want to go to a Tavern next?"
puts "Or maybe you want to go to the forest?"
My question is, why does it skip the lines when I put in "yes" for randEvent1 even though I put that it will execute the following the when statement if randEvent1 == "y" || "yes"?
This problem also occurs when I put in "no" for the case RandEvent1.
Could it be possible it is a problem with doing || in a case..when statement? Is the syntax different for the or operator in case..when than in if statements?
Case statements do not accept || like ifs do. The proper syntax for a case having two or more possible inputs is ,. So, instead of doing case 'y' || 'yes', it should be case 'y', 'yes'.

Parse form using Nokogiri and pass it to URI.encode_www_form? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
I have simple HTML form, which I got from a web page:
<form id="my">
inputs....
</form>
I need to get this form via it's ID, which I know how to do:
#get_doc = Nokogiri::HTML(page)
nb = #get_doc.at_css('#my')
maybe could i iterate via object ?
I need to get all the input values and input names into some variable, and then pass it to URI.encode_www_form.
How can I do this? How could I get all the inputs inside the form with names and values, and pass them to encode_www_form?
arr = []
# form = doc.at_css '#form'
form.css('input').each do |i|
arr << [i['name'], i['value']]
end
URI.encode_www_form arr

using # instead of . in API documentation [closed]

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 4 years ago.
Improve this question
In API documentation, and sometimes even used in discussions here on Stack Overflow, I sometimes see the pound (#) character used instead of the dot (.) as the separator between the class name and the method name. For example:
Settings#maxPageSize
I'm wondering what this usage means, and where it comes from?
Assuming you mean Ruby (which is the first language that I can think of with such conventions), it is explained here:
Why are methods in Ruby documentation preceded by a hash sign?
I've always thought that the distinction is that Settings.maxPageSize seems to imply that you can actually write just that (i.e. that it is a static method), and that the pound is there to denote that it is just a reference to a method, not a piece of code that you can execute.
Although I could be totally wrong about this =)
So for static methods, you could actually reference them Settings.maxPageSize, but for instance methods, you'd have the option of coming up with a new convention, such as Array#sort to denote that something special is going on, or, to achieve the same completeness, you'd have to write
myArray.sort // when myArray is of the type Array
EDIT
Amadan's reply seems to confirm my interpretation, with the exception that Settings.maxPageSize is not used for static methods either; rather, that would be Settings::maxPageSize, and . being reserved entirely for example code, which makes sense to me.

Resources