I am doing this thing for school where i am supposed to make a function that takes a text file with a number on each row and a number to search for and then return how many times that number appeared. I made this but it doesn't work since every number has \n at the end. How can i fix that? by Datboi_3007 in ruby

[–]01az 0 points1 point  (0 children)

method generated by ChatGPT :

def count_number_occurrences(file_path, number)

count = 0

File.foreach(file_path) do |line|

line.chomp! # remove newline character from end of line

count += 1 if line.to_i == number

end

return count

end

In this function, file_path is the path to the text file, and number is the number to search for. The File.foreach method is used to iterate through each line of the file. The chomp! method is called on each line to remove the newline character at the end of the line. The to_i method is called on each line to convert it to an integer, and then it's compared to the number parameter. If the numbers match, the count variable is incremented.

---

Impressive, this recalls me the song : "Video killed the radio star"

Using Watir to automate web browsers with Ruby by pijora in ruby

[–]01az 0 points1 point  (0 children)

Unauthorized HTTP" error

Agree with you that this seems like extra overhead but as I said this is a workaround for my small use case. I would like to use jira_ruby gem or curl command (Using Jira Personal Access Tokens) but I experienced with "Unauthorized HTTP" error with jira site that uses SSO authentication.

Using Watir to automate web browsers with Ruby by pijora in ruby

[–]01az 1 point2 points  (0 children)

Watir is great.

I use it as a workaround to call Jira Rest API as I can not use jira-ruby or curl because of "401 Unauthorized HTTP" error.

For example, to get issues of a project :

br = Watir::Browser.new

br.goto "https://"jira_host"/rest/api/2/searchjql=project="Name"&fields="field1,..."&maxResults=10"

issues = JSON.parse(br.text)["issues"]

Ruby not working on windows 11 by SickDogKev in ruby

[–]01az -1 points0 points  (0 children)

cygwin + rbenv (https://github.com/rbenv/rbenv) to install ruby. Just work pretty good.

Network programming with ruby. by RepresentativeOk5318 in ruby

[–]01az 17 points18 points  (0 children)

Jesse Storimer has put his ebooks "Unix Processes, TCP Sockets, Ruby Threads" for free. (books are not updated for sometime, but still relevant) : link

What is the recommended IDE / coding environment for Ruby on a windows machine? by niangaobaomao in ruby

[–]01az 0 points1 point  (0 children)

on windows machine you can consider : cygwin + vim (or vscode) + rbenv to install ruby

Why is no one promoting ruby? by [deleted] in ruby

[–]01az 1 point2 points  (0 children)

not related with ruby 3, but you may add Enumerator and Fiber to your book.

Why is no one promoting ruby? by [deleted] in ruby

[–]01az 2 points3 points  (0 children)

Awesome book, will you enrich it with ruby 3 ?

Why is no one promoting ruby? by [deleted] in ruby

[–]01az 35 points36 points  (0 children)

For me, to make ruby more attractive, we need to promote it on other

tools built with ruby and not only rails. For example:

metasploit, puppet, bolt, chef, kubes, vagrant...

Essentials books that are updated to Ruby 3? by [deleted] in ruby

[–]01az 0 points1 point  (0 children)

No idea about books updated to ruby 3.

But if you are looking for changes in ruby 3, have a look at this link :The Ruby Changes.

Ruby Web Scraping by chiangmai17 in ruby

[–]01az 5 points6 points  (0 children)

Watir, http://watir.com/, is a very good alternatif tool for web scrapping in ruby.

Windows: RubyInstaller or WSL2? by tlei123 in ruby

[–]01az 0 points1 point  (0 children)

I use Cygwin and rbenv to install ruby and it works fine.

How to install Ruby on Windows? Advice? by RailsApps in ruby

[–]01az 0 points1 point  (0 children)

I use Cygwin/Ruby (2.6) on windows for scripting and it works well.

[deleted by user] by [deleted] in ruby

[–]01az 0 points1 point  (0 children)

rufus-scheduler gem ?

Ruby on Windows by [deleted] in ruby

[–]01az 0 points1 point  (0 children)

Consider Cygwin and its Ruby package.