Skip to content

Add CLI and Fibonacci scripts, and implement Rectangle area calculation#129

Merged
x0lg0n merged 1 commit intomainfrom
feature/Ruby
Oct 27, 2025
Merged

Add CLI and Fibonacci scripts, and implement Rectangle area calculation#129
x0lg0n merged 1 commit intomainfrom
feature/Ruby

Conversation

@x0lg0n
Copy link
Owner

@x0lg0n x0lg0n commented Oct 27, 2025

Introduce a command-line interface for message printing, a Fibonacci sequence generator, and a Rectangle class with area calculation functionality.

Summary by Sourcery

Introduce three standalone Ruby scripts: a CLI utility for message printing, a Fibonacci sequence generator, and a Rectangle class under an Area module for computing area.

New Features:

  • Add a command-line interface script for printing a customizable message multiple times
  • Implement a Fibonacci sequence generator script that prompts for input and outputs the sequence
  • Introduce an Area module and Rectangle class with an area calculation method and demonstration

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a command-line utility with custom message printing and configurable repetition options
    • Added an interactive Fibonacci number generator tool
    • Added a geometry example demonstrating shape area calculations

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 27, 2025

Reviewer's Guide

Adds three standalone Ruby scripts: cli.rb introduces a command-line interface for customizable message printing using OptionParser; fibonacci.rb implements an iterative fib function with user input to generate and print a sequence; shapes.rb defines an Area module and a Rectangle class with area calculation and provides a usage example.

Class diagram for Area module and Rectangle class

classDiagram
  class Area {
    +area()
  }
  class Rectangle {
    +w
    +h
    +initialize(w, h)
    +area()
  }
  Rectangle --|> Area
Loading

File-Level Changes

Change Details Files
Introduce CLI for configurable message printing
  • Require 'optparse' and initialize default options
  • Define -n/--number and -m/--message flags in OptionParser
  • Set default message and repeat printing based on parsed options
Ruby/cli.rb
Add Fibonacci sequence generator script
  • Implement fib(n) using iterative tuple swapping
  • Prompt user for number of terms and parse input
  • Loop through indices to print each Fibonacci value
Ruby/fibonacci.rb
Implement Area module and Rectangle area calculation
  • Define Area module with abstract area method
  • Create Rectangle class including Area with width, height, and area implementation
  • Instantiate Rectangle and print its area in a demo
Ruby/shapes.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Unbounded input loop

Description: Unvalidated user input from STDIN is converted with to_i without bounds checking, allowing
extremely large counts that can cause excessive CPU usage and denial of service.
fibonacci.rb [8-10]

Referred Code
print "How many Fibonacci numbers? "
m = gets.to_i
(0...m).each { |i| puts "#{i}: #{fib(i)}" }
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

🔴
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing validation: External input from STDIN is not validated, allowing negative or non-integer values and
lacking error handling for edge cases.

Referred Code
print "How many Fibonacci numbers? "
m = gets.to_i
(0...m).each { |i| puts "#{i}: #{fib(i)}" }
Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Unvalidated inputs: CLI accepts unvalidated numeric and message inputs (e.g., negative or extremely large
counts) without constraints or sanitization, risking misuse and denial-of-service
behavior.

Referred Code
  opts.on("-nN", "--number=N", Integer, "Number of times") do |n|
    options[:times] = n
  end

  opts.on("-mMSG", "--message=MSG", "Message to print") do |m|
    options[:message] = m
  end
end.parse!

msg = options[:message] || "Hello"
options[:times].times { puts msg }
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No audit logs: The CLI performs user-invoked actions without recording any audit trail (no user ID,
timestamp, action, or outcome), but this may be acceptable for a simple local script.

Referred Code
  opts.on("-nN", "--number=N", Integer, "Number of times") do |n|
    options[:times] = n
  end

  opts.on("-mMSG", "--message=MSG", "Message to print") do |m|
    options[:message] = m
  end
end.parse!

msg = options[:message] || "Hello"
options[:times].times { puts msg }
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request adds three new Ruby example scripts: a CLI argument parser using OptionParser for handling message and repetition count options, a fibonacci number generator with interactive user prompts, and a geometry module with a Rectangle class implementation demonstrating area calculation.

Changes

Cohort / File(s) Summary
New Ruby Example Scripts
Ruby/cli.rb, Ruby/fibonacci.rb, Ruby/shapes.rb
Adds three standalone Ruby scripts: cli.rb implements argument parsing with -n/--number and -m/--message options; fibonacci.rb provides an iterative fib(n) function with interactive prompts to generate and display fibonacci sequences; shapes.rb defines an Area module with a Rectangle class that calculates area from width and height attributes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Input validation: No validation or error handling for user inputs in cli.rb and fibonacci.rb; consider edge cases like negative numbers or non-integer inputs
  • Error handling: fibonacci.rb and cli.rb lack try-catch or rescue blocks for unexpected inputs
  • Code robustness: shapes.rb's area method could include parameter validation

Poem

🐰 Three little scripts hop into place,
One parses flags with style and grace,
Fibonacci bounds in patterns neat,
While shapes define rectangles sweet! ✨
Ruby scripts grow, making code complete! 🌟

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/Ruby

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39e1e6d and 91828b2.

📒 Files selected for processing (3)
  • Ruby/cli.rb (1 hunks)
  • Ruby/fibonacci.rb (1 hunks)
  • Ruby/shapes.rb (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@x0lg0n x0lg0n merged commit 85d0063 into main Oct 27, 2025
1 of 3 checks passed
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `Ruby/cli.rb:4` </location>
<code_context>
+# cli.rb
+require 'optparse'
+
+options = { times: 1 }
+OptionParser.new do |opts|
+  opts.banner = "Usage: cli.rb [options]"
</code_context>

<issue_to_address>
**suggestion:** Consider validating input for negative or zero values for 'times'.

Without validation, negative or zero values for '-n'/'--number' may cause the script to fail silently or act unpredictably. Please add a check to ensure 'times' is a positive integer.
</issue_to_address>

### Comment 2
<location> `Ruby/fibonacci.rb:9` </location>
<code_context>
+end
+
+print "How many Fibonacci numbers? "
+m = gets.to_i
+(0...m).each { |i| puts "#{i}: #{fib(i)}" }
\ No newline at end of file
</code_context>

<issue_to_address>
**suggestion:** No input validation for non-integer or negative values.

Validate 'm' to ensure it is a non-negative integer to prevent unexpected behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

# cli.rb
require 'optparse'

options = { times: 1 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider validating input for negative or zero values for 'times'.

Without validation, negative or zero values for '-n'/'--number' may cause the script to fail silently or act unpredictably. Please add a check to ensure 'times' is a positive integer.

@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Improve Fibonacci sequence generation performance

Improve the performance of the Fibonacci sequence generation by replacing the
inefficient repeated calls to fib(i) inside the loop with a single, more
efficient iterative calculation.

Ruby/fibonacci.rb [2-10]

-def fib(n)
-  a, b = 0, 1
-  n.times { a, b = b, a + b }
-  a
+print "How many Fibonacci numbers? "
+m = gets.to_i
+
+a, b = 0, 1
+(0...m).each do |i|
+  puts "#{i}: #{a}"
+  a, b = b, a + b
 end
 
-print "How many Fibonacci numbers? "
-m = gets.to_i
-(0...m).each { |i| puts "#{i}: #{fib(i)}" }
-
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a significant O(n²) performance issue in the Fibonacci generation and provides an optimized O(n) solution, which is a substantial improvement.

Medium
  • More

@x0lg0n x0lg0n deleted the feature/Ruby branch January 15, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant