[Solved] Rspec pass test in ruby testing

solution.highest_count_words_across_lines is an array of strings. When you do this: solution.highest_count_words_across_lines.map(&:highest_wf_words) you are calling highest_wf_words on each of the array items, and that method is not defined for a String (that is what the error message says). I guess that in fact you want something like this instead: words_found = solution.highest_count_words_across_lines.map( |x| highest_wf_words(x)).flatten UPDATE if … Read more

[Solved] undefined method `round’ for nil:NilClass when calculating difference between dates [closed]

Introduction When calculating the difference between two dates, you may encounter the error “undefined method `round’ for nil:NilClass”. This error occurs when the difference between the two dates is nil, meaning that the two dates are the same. This error can be solved by checking if the difference between the two dates is nil before … Read more

[Solved] Separate a row of strings into separate rows [closed]

Python Power Unleased : import csv,sys filename=”a.csv” with open(filename,’rb’) as csvfile: reader = csv.reader(csvfile,delimiter=”,”) try: for row in reader: if row[1].find(‘,’) == -1: line=”,”.join(row) print line else: for i in range(0,row[1].count(‘,’)+1): line = row[0]+’,’+row[1].split(‘,’)[i]+’,’+row[2].split(‘,’)[i] print line except csv.Error as e: sys.exit(‘file %s, line %d: %s’ % (filename, reader.line_num, e)) solved Separate a row of strings … Read more

[Solved] Gets.chomp not working

You are supposed to enter values, not just press enter, when prompted after running the program: # ⇓ prompt ⇓ ⇓⇓ YOUR INPUT!!! How old are you? 35 Sidenote: parentheses after chomp are redundant and not ruby idiomatic. 0 solved Gets.chomp not working

[Solved] `Case/when` statement works some of the time

For some reason you iterate over REGEXS, ignore the item in the iteration, then hard-code them again… you actually do text.gsub(Supertag::Tag::USERTAG_REGEX) … 3 times – once for each REGEX in your list. Also, you misuse the case when construct, I suggest you read more about it You should either drop the each entirely, and use … Read more

[Solved] Ruby: call initialize method before others in class [closed]

initialize is an instance method in this class, so the def initialize is just setting up the constructor for the class. call.. is calling the class’s call method at the time the class definition is parsed. This code is equivalent to class Lol < Redstone def initialize super 2013 end end Lol.call “https://stackoverflow.com/” do |headers| … Read more

[Solved] User Input + Random Word and Number printing

input and occupation are defined outside the scope of the occupationsfunction. Either declare it as a global variable with $input and $occupation, declare it inside the function or pass the variables as arguments to the function (as Lee suggested): puts ‘What is your name?(Enter in field below)’ $input = gets.chomp puts ‘end’ occupationslist = [‘Engineer’, … Read more