Posts by taq • 104 points
5 posts
-
6
votes2
answers2880
viewsA: What is cyclomatic complexity?
Illustrated cyclomatic complexity: Think about how in this case would be the graph that @Maniero exemplified above. :-)…
-
-1
votes2
answers743
viewsA: Read file and search word
If you want to find out which letter repeats, you can do so: File.read("/tmp/teste.txt").chomp. split(/;/). reduce(Hash.new(0)) { |m, i| m[i] += 1; m }. select { |k, v| v > 1 } Upshot: =>…
-
1
votes2
answers82
viewsA: How to return null if no result is found with find_by?
The find_by always returns 1 or nil. How you switched to where, returns a collection or empty []. You can use def self.scheduled where(state: :scheduled).first end to return the first result or nil.…
-
1
votes3
answers1980
viewsA: How to find a letter in a string?
If you just want to know if it includes the lyrics: "palavra".include?("a") If you want the number of times it appears: "palavra".count("a")
-
1
votes1
answer604
viewsA: Undefined method `id' for nil:Nilclass
It’s got a hell of a face to be a method new in a controller of a Rails application where @page would be being initialized somewhere out of of the method, probably in a before_action. If you don’t…