Skip to content

Commit

Permalink
adding for local file access at github
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadalmustafa committed Apr 13, 2024
1 parent fabf1f5 commit 3c610b4
Show file tree
Hide file tree
Showing 13 changed files with 651 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@

Welcome to our comprehensive Ruby programming course. Below you will find links to each chapter that will guide you through the different aspects of Ruby programming.


## Course Chapters

1. [Introduction to Ruby](./chapters/chapter_01.md)
2. [Setting Up Your Ruby Environment](./chapters/chapter_02.md)
3. [Basic Ruby Syntax and Operations](./chapters/chapter_03.md)
4. [Control Structures and Loops](./chapters/chapter_04.md)
5. [Methods and Return Values](./chapters/chapter_05.md)
6. [Working with Arrays and Hashes](./chapters/chapter_06.md)
7. [Object-Oriented Programming in Ruby](./chapters/chapter_07.md)
8. [Error Handling and Debugging](./chapters/chapter_08.md)
9. [File Input/Output](./chapters/chapter_09.md)
10. [Advanced Ruby Features](./chapters/chapter_10.md)


---

## Course Chapters for sintra run

1. [Introduction to Ruby](./chapter01)
2. [Setting Up Your Ruby Environment](./chapter02)
3. [Basic Ruby Syntax and Operations](./chapter03)
Expand All @@ -13,4 +30,4 @@ Welcome to our comprehensive Ruby programming course. Below you will find links
7. [Object-Oriented Programming in Ruby](./chapter07)
8. [Error Handling and Debugging](./chapter08)
9. [File Input/Output](./chapter09)
10. [Advanced Ruby Features](./chapter10)# ruby_course
10. [Advanced Ruby Features](./chapter10)# ruby_course
19 changes: 19 additions & 0 deletions app.rb
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
18 changes: 18 additions & 0 deletions chapters/chapter_01.md
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!"
```
25 changes: 25 additions & 0 deletions chapters/chapter_02.md
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
```
40 changes: 40 additions & 0 deletions chapters/chapter_03.md
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
```
46 changes: 46 additions & 0 deletions chapters/chapter_04.md
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
```
55 changes: 55 additions & 0 deletions chapters/chapter_05.md
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)

```
79 changes: 79 additions & 0 deletions chapters/chapter_06.md
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

```
Loading

0 comments on commit 3c610b4

Please sign in to comment.