-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding for local file access at github
- Loading branch information
1 parent
fabf1f5
commit 3c610b4
Showing
13 changed files
with
651 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'sinatra' | ||
require 'redcarpet' # This is a Markdown to HTML converter | ||
|
||
# Setup Redcarpet (Markdown parser) | ||
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML) | ||
|
||
# Define routes for each chapter | ||
get '/' do | ||
markdown.render(File.read('README.md')) | ||
end | ||
|
||
(1..10).each do |chapter_number| | ||
formatted_number = format('%02d', chapter_number) | ||
get "/chapter#{formatted_number}" do | ||
puts "chapter formatted number #{formatted_number}" | ||
file_path = "chapters/chapter_0#{chapter_number}.md" | ||
markdown.render(File.read(file_path)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Chapter 1: Introduction to Ruby | ||
|
||
## Overview | ||
In this chapter, we'll explore what Ruby is, its history, and why it's a popular choice among programmers. We'll also briefly discuss Ruby's role in web development and other fields. | ||
|
||
## Why Ruby? | ||
Ruby is known for its elegant syntax that is natural to read and easy to write. Here are a few reasons why Ruby is a favorite among developers: | ||
- Easy to learn | ||
- Highly expressive language | ||
- Large and active community | ||
- Powerful framework support (e.g., Ruby on Rails) | ||
|
||
## A Simple Ruby Program | ||
Here's how you can print "Hello, World!" in Ruby: | ||
|
||
```ruby | ||
puts "Hello, World!" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Chapter 2: Setting Up Your Ruby Environment | ||
|
||
## Overview | ||
This chapter guides you through the process of setting up Ruby on different operating systems, including Windows, macOS, and Linux. | ||
|
||
## Installing Ruby | ||
### Windows | ||
1. Download Ruby Installer from [RubyInstaller](https://rubyinstaller.org/). | ||
2. Follow the on-screen instructions to install. | ||
|
||
### macOS | ||
1. Use Homebrew by running: `brew install ruby` | ||
|
||
### Linux (Ubuntu) | ||
1. Run: `sudo apt-get install ruby-full` | ||
|
||
## Setting Up Your Development Environment | ||
Choose a code editor like VS Code or Atom, and install necessary Ruby plugins or extensions. | ||
|
||
## Testing Your Installation | ||
Run the following command in your terminal or command prompt to check Ruby version: | ||
|
||
```bash | ||
ruby -v | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
### `chapter_03.md` (Basic Ruby Syntax and Operations) | ||
|
||
|
||
# Chapter 3: Basic Ruby Syntax and Operations | ||
|
||
## Overview | ||
This chapter introduces the basic syntax and operations in Ruby. | ||
|
||
## Basic Syntax | ||
Ruby has a clean, easy-to-read syntax that makes programming pleasant. Here are some fundamentals: | ||
|
||
### Variables | ||
dfafa | ||
|
||
```ruby | ||
name = "Ruby" | ||
age = 30 | ||
``` | ||
|
||
### Data types | ||
|
||
Ruby automatically determines the type based on the assigned value. | ||
|
||
|
||
### methods | ||
Methods in Ruby are defined using the def keyword. | ||
```ruby | ||
def greet(name) | ||
puts "Hello, #{name}!" | ||
end | ||
``` | ||
|
||
### Arithmetic operations | ||
Ruby supports all standard arithmetic operations. | ||
|
||
```ruby | ||
sum = 1 + 2 # addition | ||
product = 3 * 4 # multiplication | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
### `chapter_04.md` (Control Structures and Loops) | ||
|
||
# Chapter 4: Control Structures and Loops | ||
|
||
## Overview | ||
Control structures and loops are fundamental in programming. This chapter covers their use in Ruby. | ||
|
||
## Conditional Statements | ||
### If Statement | ||
|
||
```ruby | ||
if temperature > 30 | ||
puts "It's hot outside!" | ||
elsif temperature < 10 | ||
puts "It's cold outside!" | ||
else | ||
puts "The weather is nice!" | ||
end | ||
``` | ||
|
||
|
||
### Unless Statement | ||
```ruby | ||
unless sun.shining? | ||
puts "It might rain today." | ||
end | ||
``` | ||
|
||
|
||
## Loops | ||
### While Loop | ||
```ruby | ||
while counter < 5 do | ||
puts "Counter at #{counter}" | ||
counter += 1 | ||
end | ||
``` | ||
|
||
|
||
### Times Loop | ||
```ruby | ||
5.times do |i| | ||
puts "Iteration #{i}" | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Chapter 5: Methods and Return Values | ||
|
||
## Overview | ||
Methods are crucial for organizing and reusing code in Ruby. This chapter covers how to define methods, pass parameters, handle return values, and best practices for using methods in Ruby programming. | ||
|
||
## Defining Methods | ||
In Ruby, you define a method using the `def` keyword, followed by the method name and any parameters. Here is a simple example: | ||
|
||
```ruby | ||
def greet(name) | ||
puts "Hello, #{name}!" | ||
end | ||
``` | ||
|
||
You can call this method by passing the required argument like this: | ||
|
||
```ruby | ||
greet("Alice") | ||
``` | ||
|
||
## Parameters | ||
Methods can take multiple parameters, separated by commas. Here's an example of a method that takes two parameters: | ||
```ruby | ||
def add(a, b) | ||
puts "The sum is #{a + b}" | ||
end | ||
|
||
add(5, 3) | ||
``` | ||
|
||
|
||
## Default Parameters | ||
You can also define default values for parameters that will be used if no argument is provided for that parameter: | ||
|
||
```ruby | ||
def greet(name, greeting="Hello") | ||
puts "#{greeting}, #{name}!" | ||
end | ||
|
||
greet("Alice") # Outputs: Hello, Alice! | ||
greet("Alice", "Hi") # Outputs: Hi, Alice! | ||
``` | ||
|
||
## Return Values | ||
In Ruby, a method returns the result of the last expression evaluated, but you can also use return to return a value early: | ||
|
||
```ruby | ||
def largest_number(a, b) | ||
return a if a > b | ||
b | ||
end | ||
|
||
puts largest_number(5, 10) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Chapter 6: Working with Arrays and Hashes | ||
|
||
## Overview | ||
Arrays and hashes are essential data structures in Ruby used to organize and store data. This chapter explores how to create, access, and manipulate these structures effectively. | ||
|
||
## Arrays | ||
Arrays in Ruby are ordered, integer-indexed collections of any object. Here's how to create and manipulate an array: | ||
|
||
### Creating Arrays | ||
```ruby | ||
numbers = [1, 2, 3, 4, 5] | ||
names = ["Alice", "Bob", "Charlie"] | ||
``` | ||
|
||
|
||
### Accessing Elements | ||
Elements in an array are accessed by their index: | ||
|
||
```ruby | ||
puts numbers[0] # Outputs 1 | ||
puts names[2] # Outputs Charlie | ||
|
||
``` | ||
|
||
### Adding Elements | ||
You can add elements to arrays using push or the << operator: | ||
|
||
```ruby | ||
numbers.push(6) | ||
names << "David" | ||
``` | ||
|
||
### Iterating Over Arrays | ||
|
||
Use each to iterate over elements: | ||
```ruby | ||
names.each do |name| | ||
puts "Hello, #{name}!" | ||
end | ||
|
||
``` | ||
|
||
## Hashes | ||
Hashes in Ruby are collections of key-value pairs. They are similar to dictionaries in other languages. | ||
|
||
|
||
### Creating Hashes | ||
|
||
```ruby | ||
ages = { "Alice" => 30, "Bob" => 25, "Charlie" => 35 } | ||
|
||
``` | ||
|
||
### Accessing Values | ||
|
||
Access values in a hash by using their keys: | ||
|
||
```ruby | ||
|
||
puts ages["Alice"] # Outputs 30 | ||
|
||
``` | ||
|
||
### Adding Key-Value Pairs | ||
Add new pairs to hashes like this: | ||
|
||
```ruby | ||
ages["David"] = 28 | ||
``` | ||
|
||
### Iterating Over Hashes | ||
Iterate over key-value pairs using each: | ||
|
||
```ruby | ||
ages.each do |name, age| | ||
puts "#{name} is #{age} years old." | ||
end | ||
|
||
``` |
Oops, something went wrong.