Skip to content

Commit 6ba3a4a

Browse files
committed
Concept Cleanup for Single Sentence per line
1 parent 93f64f9 commit 6ba3a4a

27 files changed

Lines changed: 133 additions & 62 deletions

File tree

concepts/arrays/about.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# About
22

3-
Data structures that can hold zero or more elements are known as _collections_. An **array** in Ruby is a collection that maintains the ordering in which its objects are added. Arrays can hold any object. Objects can be added to an array or retrieved from it using an index. Ruby array indexing is zero-based, meaning that the first element's index is always zero:
3+
Data structures that can hold zero or more elements are known as _collections_.
4+
An **array** in Ruby is a collection that maintains the ordering in which its objects are added.
5+
Arrays can hold any object.
6+
Objects can be added to an array or retrieved from it using an index.
7+
Ruby array indexing is zero-based, meaning that the first element's index is always zero:
48

59
```ruby
610
# Declare an array containing two values

concepts/arrays/introduction.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Introduction
22

3-
In Ruby, **arrays** are ordered, integer-indexed collections of any object. Array indexing starts at `0`. A negative index is assumed to be relative to the end of the array — i.e. an index of `-1` indicates the last element of the array, `-2` is the next to last element in the array, and so on.
3+
In Ruby, **arrays** are ordered, integer-indexed collections of any object.
4+
Array indexing starts at `0`.
5+
A negative index is assumed to be relative to the end of the array — i.e., an index of `-1` indicates the last element of the array, `-2` is the next to last element in the array, and so on.
46
Ruby arrays mix in the [Enumerable module][enumerable-module], which adds several traversal and searching methods, and with the ability to sort.
57

68
## Create Array
@@ -13,7 +15,8 @@ array = [1, "two", 3.0] #=> [1, "two", 3.0]
1315

1416
## Element Assignment
1517

16-
Elements can be accessed or changed using indexes. Subarrays can be accessed by specifying a start index and a size.
18+
Elements can be accessed or changed using indexes.
19+
Subarrays can be accessed by specifying a start index and a size.
1720

1821
```ruby
1922
a = ["", "", "", "", ""]
@@ -33,7 +36,8 @@ a #=> ["a", "Z"]
3336

3437
## Element Reference
3538

36-
- Elements in an array can be retrieved using the #[] method. It returns the element at index, or returns a subarray starting at the start index and continuing for length elements.
39+
- Elements in an array can be retrieved using the #[] method.
40+
- It returns the element at index, or returns a subarray starting at the start index and continuing for length elements.
3741

3842
```ruby
3943
a = [ "a", "b", "c", "d", "e" ]
@@ -54,7 +58,8 @@ a[-3, 3] #=> [ "c", "d", "e" ]
5458

5559
## Obtaining Information about an Array
5660

57-
Arrays keep track of their own length at all times. To query an array about the number of elements it contains, use length, count or size.
61+
Arrays keep track of their own length at all times.
62+
To query an array about the number of elements it contains, use length, count or size.
5863

5964
```ruby
6065
browsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'IE']
@@ -65,7 +70,7 @@ browsers.size #=> 5
6570

6671
## Adding Items to Arrays
6772

68-
Items can be added to the end of an array by using either push or <<
73+
Items can be added to the end of an array by using either `push` or `<<`:
6974

7075
```ruby
7176
arr = [1, 2, 3, 4]
@@ -75,10 +80,10 @@ arr << 6 #=> [1, 2, 3, 4, 5, 6]
7580

7681
## Removing Items from an Array
7782

78-
The method pop removes the last element in an array and returns it
83+
The method pop removes the last element in an array and returns it:
7984

8085
```ruby
81-
arr = [1, 2, 3, 4, 5, 6]
86+
arr = [1, 2, 3, 4, 5, 6]
8287
arr.pop #=> 6
8388
arr #=> [1, 2, 3, 4, 5]
8489
```

concepts/basics/about.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# About
22

3-
Ruby is a dynamic and strongly typed language. In dynamic languages the type of a variable or object is resolved at runtime, which means that its value or type can be changed up to the very last moment (when it gets parsed by the interpreter).
4-
And what do we mean with strongly typed? Once we know the type of a variable or object, Ruby is strict about what you can do with it, for example:
3+
Ruby is a dynamic and strongly typed language.
4+
In dynamic languages the type of a variable or object is resolved at runtime, which means that its value or type can be changed up to the very last moment (when it gets parsed by the interpreter).
5+
And what do we mean with strongly typed?
6+
Once we know the type of a variable or object, Ruby is strict about what you can do with it, for example:
57

68
```ruby
79
x = '2'
810
y = x + 'n'
9-
# => '2n'
11+
# => '2n'
1012
```
1113

1214
**But**
@@ -17,7 +19,10 @@ y = x + 2
1719
# => TypeError (no implicit conversion of Integer into String)
1820
```
1921

20-
Remember, in Ruby everything is an object. Even classes are instances of the class `Class`. For example:
22+
Remember, in Ruby everything is an object.
23+
Even classes are instances of the class `Class`.
24+
25+
For example:
2126

2227
```ruby
2328
1.class

concepts/basics/introduction.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# Introduction
22

3-
Ruby is a dynamic [object-oriented language][object-oriented-programming]. Everything in Ruby is an [object][object].
3+
Ruby is a dynamic [object-oriented language][object-oriented-programming].
4+
Everything in Ruby is an [object][object].
45

5-
There are two primary ways to assign objects to names in Ruby - using variables or constants. Variables are always written in [snake case][snake-case]. A variable can reference different objects over its lifetime. For example, `my_first_variable` can be defined and redefined many times using the `=` operator:
6+
There are two primary ways to assign objects to names in Ruby - using variables or constants.
7+
Variables are always written in [snake case][snake-case].
8+
A variable can reference different objects over its lifetime.
9+
For example, `my_first_variable` can be defined and redefined many times using the `=` operator:
610

711
```ruby
812
my_first_variable = 1
913
my_first_variable = "Some string"
1014
my_first_variable = SomeComplexObject.new
1115
```
1216

13-
Constants, however, are meant to be assigned once. They must start with capital letters and are normally written in block capitals with words separated by underscores. For example:
17+
Constants, however, are meant to be assigned once.
18+
They must start with capital letters and are normally written in block capitals with words separated by underscores.
19+
20+
For example:
1421

1522
```ruby
1623
MY_FIRST_CONSTANT = 10
@@ -19,7 +26,11 @@ MY_FIRST_CONSTANT = 10
1926
# MY_FIRST_CONSTANT = "Some String"
2027
```
2128

22-
Ruby is organised into classes. Classes are defined using the `class` keyword followed by the name of the class. Objects are generally created by instantiating classes using the `.new` method. For example:
29+
Ruby is organised into classes.
30+
Classes are defined using the `class` keyword followed by the name of the class.
31+
Objects are generally created by instantiating classes using the `.new` method.
32+
33+
For example:
2334

2435
```ruby
2536
# Define the class
@@ -31,7 +42,10 @@ end
3142
my_first_calc = Calculator.new
3243
```
3344

34-
Units of functionality are encapsulated in methods - similar to _functions_ in other languages. A method can optionally be defined with positional arguments, and/or keyword arguments that are defined and called using the `:` syntax. Methods either implicitly return the result of the last evaluated statement, or can explicitly return an object via the `return` keyword. Methods are invoked using `.` syntax.
45+
Units of functionality are encapsulated in methods - similar to _functions_ in other languages.
46+
A method can optionally be defined with positional arguments, and/or keyword arguments that are defined and called using the `:` syntax.
47+
Methods either implicitly return the result of the last evaluated statement, or can explicitly return an object via the `return` keyword.
48+
Methods are invoked using `.` syntax.
3549

3650
```ruby
3751
class Calculator

concepts/blocks/about.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# About
22

3-
Blocks are small groupings of statements that can be executed multiple times.
4-
They can be thought of as closures or anonymous functions.
5-
Blocks are defined using the `do...end` syntax (above), or the `{}` (below).
3+
Blocks are small groupings of statements that can be executed multiple times.
4+
They can be thought of as closures or anonymous functions.
5+
Blocks are defined using the `do...end` syntax (above), or the `{}` (below).
66
The styles are interchangeable and differing opinions exist about when each should be used.
77

88
## Shortcut Syntax

concepts/blocks/introduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Introduction
22

3-
Blocks are small groupings of statements that can be executed multiple times.
4-
They can be thought of as closures or anonymous functions.
5-
Blocks are defined using the `do...end` syntax (above), or the `{}` (below).
3+
Blocks are small groupings of statements that can be executed multiple times.
4+
They can be thought of as closures or anonymous functions.
5+
Blocks are defined using the `do...end` syntax (above), or the `{}` (below).
66
The styles are interchangeable and differing opinions exist about when each should be used.

concepts/booleans/introduction.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## True and False
44

5-
True and false logical states are represented with `true` and `false` in Ruby. These may either be used as literals on their own, or as a result of logical or comparison methods.
5+
True and false logical states are represented with `true` and `false` in Ruby.
6+
These may either be used as literals on their own, or as a result of logical or comparison methods.
67

78
```ruby
89
happy = true
@@ -21,7 +22,8 @@ When evaluating objects in `if` statements or other boolean contexts, all object
2122

2223
## Control flow
2324

24-
_Truthy_ and _falsey_ evaluations are useful in the context of control flow. Like in procedural languages, Ruby has an `if`...`else` construct, but it may be more common to use `if` as a "guarding" statement to modify the evaluation of an expression.
25+
_Truthy_ and _falsey_ evaluations are useful in the context of control flow.
26+
Like in procedural languages, Ruby has an `if`...`else` construct, but it may be more common to use `if` as a "guarding" statement to modify the evaluation of an expression.
2527

2628
```ruby
2729
def falsey
@@ -49,7 +51,8 @@ end
4951
# the numbers are not added because of the modifier, nil is returned
5052
```
5153

52-
Ruby provides `unless` to make code read well. E.g.) Rather than `eat_desert if not too_full`, we can also write `eat_desert unless too_full`.
54+
Ruby provides `unless` to make code read well.
55+
E.g.) Rather than `eat_desert if not too_full`, we can also write `eat_desert unless too_full`.
5356

5457
```ruby
5558
3 + 3 unless truthy

concepts/exceptions/about.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ We do this using the `raise` method, passing in an object - normally an Exceptio
88
For example, you'll see in the exercise stubs that we use the built-in `RuntimeError` to tell Ruby that a method hasn't been implemented.
99
You can also use the shorthand syntax of `raise(ExceptionObject, params)`.
1010
If the exception class is omitted, `RuntimeError` is used by default.
11+
1112
For example:
1213

1314
```ruby
@@ -18,7 +19,9 @@ raise "Please implement this method"
1819
```
1920

2021
When Ruby sees this it bubbles the error to the top of the program and then exits.
22+
2123
For example, if you try dividing something by zero, you will see something like this:
24+
2225
```ruby
2326
5/0
2427

@@ -32,7 +35,8 @@ Exceptions should not be used for control-flow of a program, as that is consider
3235

3336
## Class hierarchy
3437

35-
In Ruby exceptions follow a class hierarchy where `Exception` is the base class. These are the most common Ruby's built-in exceptions:
38+
In Ruby exceptions follow a class hierarchy where `Exception` is the base class.
39+
These are the most common Ruby's built-in exceptions:
3640

3741
```
3842
Exception
@@ -64,7 +68,8 @@ Exception
6468
SystemExit
6569
```
6670

67-
Rescuing errors of a specific class also rescues errors of its children. This is why rescuing from `Exception` can be dangerous.
71+
Rescuing errors of a specific class also rescues errors of its children.
72+
This is why rescuing from `Exception` can be dangerous.
6873
Ruby uses exceptions to also handle messages from the operative system "Signals", for example `ctrl-c`.
6974
This means that rescuing from `Exception` will also capture this system "Signals".
7075
So in order to prevent unexpected behaviours the common practice to capture "all errors" is to rescue form `StandardError`.

concepts/exceptions/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Exceptions are a form of error handling.
44
They are called exceptions, as they normally appear when dealing with some unexpected event.
55

6-
At any point in our code, we can "raise" an exception.
6+
At any point in our code, we can "raise" an exception.
77
We do this using the `raise` method, passing in an object - normally an Exception object, although we can also use basic strings.
88
For example, you'll see in the exercise stubs that we use the built-in `RuntimeError` to tell Ruby that a method hasn't been implemented.
99
You can also use the shorthand syntax of `raise(ExceptionObject, params)`.

concepts/floating-point-numbers/about.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# About
22

3-
A floating-point number is a number with zero or more digits behind the decimal separator. Examples are `4.0`, `0.1`, `3.14`, `-6.4` `16.984025` and `1024.0`. In Ruby, floating-point numbers are implemented through the [Float][Float] class.
3+
A floating-point number is a number with zero or more digits behind the decimal separator.
4+
Examples are `4.0`, `0.1`, `3.14`, `-6.4` `16.984025` and `1024.0`.
5+
In Ruby, floating-point numbers are implemented through the [Float][Float] class.
46

57
You can find a short introduction to floating-point numbers at [0.30000000000000004.com][0.30000000000000004.com].
68

79
The [Float Toy page][evanw.github.io-float-toy] has a nice, graphical explanation how a floating-point numbers' bits are converted to an actual floating-point value.
810

9-
To repeatedly execute logic, one can use loops. In this example the `while` loop is useful because it keeps on looping _while_ a condition evaluates to some truthy value (i.e. not `false` or `nil`). Ruby implements a loop similar to the `while` loop. It's called the `until` loop, and you've probably guessed what it does. It keeps looping _until_ a boolean condition evaluates to `true`. In some languages, to make a piece of code execute an unlimited number of times, constructs like `while true` are used. In Ruby, the `loop` loop exists for that purpose. Even though the `loop` loop does not depend on a single condition, it can be canceled by using a `return` or `break` keyword.
11+
To repeatedly execute logic, one can use loops.
12+
In this example the `while` loop is useful because it keeps on looping _while_ a condition evaluates to some truthy value (i.e. not `false` or `nil`).
13+
Ruby implements a loop similar to the `while` loop.
14+
It's called the `until` loop, and you've probably guessed what it does.
15+
It keeps looping _until_ a boolean condition evaluates to `true`.
16+
In some languages, to make a piece of code execute an unlimited number of times, constructs like `while true` are used.
17+
In Ruby, the `loop` loop exists for that purpose.
18+
Even though the `loop` loop does not depend on a single condition, it can be canceled by using a `return` or `break` keyword.
1019

1120
The `#years_before_desired_balance` method from the previous exercise could have been written by using any of the three mentioned loops:
1221

@@ -49,7 +58,8 @@ def self.years_before_desired_balance(current_balance, desired_balance)
4958
end
5059
```
5160

52-
As you have probably noticed, Ruby has no increment operator (`i++`) like some other languages do. Instead, constructs like `i += 1` (which is equal to `i = i + 1`) can be used.
61+
As you have probably noticed, Ruby has no increment operator (`i++`) like some other languages do.
62+
Instead, constructs like `i += 1` (which is equal to `i = i + 1`) can be used.
5363

5464
[Float]: https://docs.ruby-lang.org/en/master/Float.html
5565
[0.30000000000000004.com]: https://0.30000000000000004.com/

0 commit comments

Comments
 (0)