From 6ba3a4a387c121775c8fb0b7b602ccadf8410922 Mon Sep 17 00:00:00 2001 From: KOTP Date: Sun, 29 Mar 2026 14:55:10 -0500 Subject: [PATCH] Concept Cleanup for Single Sentence per line --- concepts/arrays/about.md | 6 ++++- concepts/arrays/introduction.md | 19 +++++++++------ concepts/basics/about.md | 13 ++++++---- concepts/basics/introduction.md | 24 +++++++++++++++---- concepts/blocks/about.md | 6 ++--- concepts/blocks/introduction.md | 6 ++--- concepts/booleans/introduction.md | 9 ++++--- concepts/exceptions/about.md | 9 +++++-- concepts/exceptions/introduction.md | 2 +- concepts/floating-point-numbers/about.md | 16 ++++++++++--- .../floating-point-numbers/introduction.md | 3 ++- concepts/instance-variables/about.md | 3 ++- concepts/loops/about.md | 3 ++- concepts/modules/about.md | 3 ++- concepts/modules/introduction.md | 3 ++- .../about.md | 3 +-- concepts/nil/about.md | 4 +++- concepts/nil/introduction.md | 5 ++-- concepts/numbers/about.md | 10 +++++--- concepts/numbers/introduction.md | 10 +++++--- concepts/ostruct/about.md | 7 ++++-- concepts/ostruct/introduction.md | 7 ++++-- concepts/ranges/about.md | 7 +++--- concepts/strings/about.md | 6 +++-- concepts/strings/introduction.md | 3 ++- concepts/ternary-operator/about.md | 4 ++-- concepts/ternary-operator/introduction.md | 4 ++-- 27 files changed, 133 insertions(+), 62 deletions(-) diff --git a/concepts/arrays/about.md b/concepts/arrays/about.md index f788003a70..4b8f112fa1 100644 --- a/concepts/arrays/about.md +++ b/concepts/arrays/about.md @@ -1,6 +1,10 @@ # About -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: +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: ```ruby # Declare an array containing two values diff --git a/concepts/arrays/introduction.md b/concepts/arrays/introduction.md index 83faff18c3..28fa779cb5 100644 --- a/concepts/arrays/introduction.md +++ b/concepts/arrays/introduction.md @@ -1,6 +1,8 @@ # Introduction -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. +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. Ruby arrays mix in the [Enumerable module][enumerable-module], which adds several traversal and searching methods, and with the ability to sort. ## Create Array @@ -13,7 +15,8 @@ array = [1, "two", 3.0] #=> [1, "two", 3.0] ## Element Assignment -Elements can be accessed or changed using indexes. Subarrays can be accessed by specifying a start index and a size. +Elements can be accessed or changed using indexes. +Subarrays can be accessed by specifying a start index and a size. ```ruby a = ["", "", "", "", ""] @@ -33,7 +36,8 @@ a #=> ["a", "Z"] ## Element Reference -- 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. +- 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. ```ruby a = [ "a", "b", "c", "d", "e" ] @@ -54,7 +58,8 @@ a[-3, 3] #=> [ "c", "d", "e" ] ## Obtaining Information about an Array -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. +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. ```ruby browsers = ['Chrome', 'Firefox', 'Safari', 'Opera', 'IE'] @@ -65,7 +70,7 @@ browsers.size #=> 5 ## Adding Items to Arrays -Items can be added to the end of an array by using either push or << +Items can be added to the end of an array by using either `push` or `<<`: ```ruby arr = [1, 2, 3, 4] @@ -75,10 +80,10 @@ arr << 6 #=> [1, 2, 3, 4, 5, 6] ## Removing Items from an Array -The method pop removes the last element in an array and returns it +The method pop removes the last element in an array and returns it: ```ruby -arr = [1, 2, 3, 4, 5, 6] +arr = [1, 2, 3, 4, 5, 6] arr.pop #=> 6 arr #=> [1, 2, 3, 4, 5] ``` diff --git a/concepts/basics/about.md b/concepts/basics/about.md index 7eb2ad5ef4..a6eeeb8861 100644 --- a/concepts/basics/about.md +++ b/concepts/basics/about.md @@ -1,12 +1,14 @@ # About -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). -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: +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). +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: ```ruby x = '2' y = x + 'n' -# => '2n' +# => '2n' ``` **But** @@ -17,7 +19,10 @@ y = x + 2 # => TypeError (no implicit conversion of Integer into String) ``` -Remember, in Ruby everything is an object. Even classes are instances of the class `Class`. For example: +Remember, in Ruby everything is an object. +Even classes are instances of the class `Class`. + +For example: ```ruby 1.class diff --git a/concepts/basics/introduction.md b/concepts/basics/introduction.md index e3e2cbc13b..5d3ca3d412 100644 --- a/concepts/basics/introduction.md +++ b/concepts/basics/introduction.md @@ -1,8 +1,12 @@ # Introduction -Ruby is a dynamic [object-oriented language][object-oriented-programming]. Everything in Ruby is an [object][object]. +Ruby is a dynamic [object-oriented language][object-oriented-programming]. +Everything in Ruby is an [object][object]. -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: +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: ```ruby my_first_variable = 1 @@ -10,7 +14,10 @@ my_first_variable = "Some string" my_first_variable = SomeComplexObject.new ``` -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: +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: ```ruby MY_FIRST_CONSTANT = 10 @@ -19,7 +26,11 @@ MY_FIRST_CONSTANT = 10 # MY_FIRST_CONSTANT = "Some String" ``` -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: +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: ```ruby # Define the class @@ -31,7 +42,10 @@ end my_first_calc = Calculator.new ``` -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. +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. ```ruby class Calculator diff --git a/concepts/blocks/about.md b/concepts/blocks/about.md index e6d7970f49..f48ab76c63 100644 --- a/concepts/blocks/about.md +++ b/concepts/blocks/about.md @@ -1,8 +1,8 @@ # About -Blocks are small groupings of statements that can be executed multiple times. -They can be thought of as closures or anonymous functions. -Blocks are defined using the `do...end` syntax (above), or the `{}` (below). +Blocks are small groupings of statements that can be executed multiple times. +They can be thought of as closures or anonymous functions. +Blocks are defined using the `do...end` syntax (above), or the `{}` (below). The styles are interchangeable and differing opinions exist about when each should be used. ## Shortcut Syntax diff --git a/concepts/blocks/introduction.md b/concepts/blocks/introduction.md index 06b2a07223..56a687a4f8 100644 --- a/concepts/blocks/introduction.md +++ b/concepts/blocks/introduction.md @@ -1,6 +1,6 @@ # Introduction -Blocks are small groupings of statements that can be executed multiple times. -They can be thought of as closures or anonymous functions. -Blocks are defined using the `do...end` syntax (above), or the `{}` (below). +Blocks are small groupings of statements that can be executed multiple times. +They can be thought of as closures or anonymous functions. +Blocks are defined using the `do...end` syntax (above), or the `{}` (below). The styles are interchangeable and differing opinions exist about when each should be used. diff --git a/concepts/booleans/introduction.md b/concepts/booleans/introduction.md index 38d979dd1b..b8921d3776 100644 --- a/concepts/booleans/introduction.md +++ b/concepts/booleans/introduction.md @@ -2,7 +2,8 @@ ## True and False -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. +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. ```ruby happy = true @@ -21,7 +22,8 @@ When evaluating objects in `if` statements or other boolean contexts, all object ## Control flow -_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. +_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. ```ruby def falsey @@ -49,7 +51,8 @@ end # the numbers are not added because of the modifier, nil is returned ``` -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`. +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`. ```ruby 3 + 3 unless truthy diff --git a/concepts/exceptions/about.md b/concepts/exceptions/about.md index 9183d71bbc..0f95ff3c16 100644 --- a/concepts/exceptions/about.md +++ b/concepts/exceptions/about.md @@ -8,6 +8,7 @@ We do this using the `raise` method, passing in an object - normally an Exceptio 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. You can also use the shorthand syntax of `raise(ExceptionObject, params)`. If the exception class is omitted, `RuntimeError` is used by default. + For example: ```ruby @@ -18,7 +19,9 @@ raise "Please implement this method" ``` When Ruby sees this it bubbles the error to the top of the program and then exits. + For example, if you try dividing something by zero, you will see something like this: + ```ruby 5/0 @@ -32,7 +35,8 @@ Exceptions should not be used for control-flow of a program, as that is consider ## Class hierarchy -In Ruby exceptions follow a class hierarchy where `Exception` is the base class. These are the most common Ruby's built-in exceptions: +In Ruby exceptions follow a class hierarchy where `Exception` is the base class. +These are the most common Ruby's built-in exceptions: ``` Exception @@ -64,7 +68,8 @@ Exception SystemExit ``` -Rescuing errors of a specific class also rescues errors of its children. This is why rescuing from `Exception` can be dangerous. +Rescuing errors of a specific class also rescues errors of its children. +This is why rescuing from `Exception` can be dangerous. Ruby uses exceptions to also handle messages from the operative system "Signals", for example `ctrl-c`. This means that rescuing from `Exception` will also capture this system "Signals". So in order to prevent unexpected behaviours the common practice to capture "all errors" is to rescue form `StandardError`. diff --git a/concepts/exceptions/introduction.md b/concepts/exceptions/introduction.md index 9a9a12c847..7d4f3c8b4a 100644 --- a/concepts/exceptions/introduction.md +++ b/concepts/exceptions/introduction.md @@ -3,7 +3,7 @@ Exceptions are a form of error handling. They are called exceptions, as they normally appear when dealing with some unexpected event. -At any point in our code, we can "raise" an exception. +At any point in our code, we can "raise" an exception. We do this using the `raise` method, passing in an object - normally an Exception object, although we can also use basic strings. 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. You can also use the shorthand syntax of `raise(ExceptionObject, params)`. diff --git a/concepts/floating-point-numbers/about.md b/concepts/floating-point-numbers/about.md index 7ce8634534..0e918bf8c9 100644 --- a/concepts/floating-point-numbers/about.md +++ b/concepts/floating-point-numbers/about.md @@ -1,12 +1,21 @@ # About -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. +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. You can find a short introduction to floating-point numbers at [0.30000000000000004.com][0.30000000000000004.com]. 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. -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. +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. The `#years_before_desired_balance` method from the previous exercise could have been written by using any of the three mentioned loops: @@ -49,7 +58,8 @@ def self.years_before_desired_balance(current_balance, desired_balance) end ``` -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. +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. [Float]: https://docs.ruby-lang.org/en/master/Float.html [0.30000000000000004.com]: https://0.30000000000000004.com/ diff --git a/concepts/floating-point-numbers/introduction.md b/concepts/floating-point-numbers/introduction.md index cbf3e74bdb..20b704ee6a 100644 --- a/concepts/floating-point-numbers/introduction.md +++ b/concepts/floating-point-numbers/introduction.md @@ -1,6 +1,7 @@ # Loops -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`. +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. [Float]: https://docs.ruby-lang.org/en/master/Float.html diff --git a/concepts/instance-variables/about.md b/concepts/instance-variables/about.md index cd66c749ea..cb225a401d 100644 --- a/concepts/instance-variables/about.md +++ b/concepts/instance-variables/about.md @@ -23,7 +23,8 @@ class Backpack end ``` -- Methods named with a trailing `=` are recognized as setters by Ruby, and allow the syntactic "sugar" use of the assignment syntax, e.g. `Backpack.new("Sven").owner = "Ayah"`. Notice the space between `owner` and `=` while the actual method name is `owner=`. +- Methods named with a trailing `=` are recognized as setters by Ruby, and allow the syntactic "sugar" use of the assignment syntax, e.g. `Backpack.new("Sven").owner = "Ayah"`. + Notice the space between `owner` and `=` while the actual method name is `owner=`. - Getters and setters can be created using the `attr_reader`, `attr_writer`, and `attr_accessor` methods: - `attr_reader`: Create getters for the symbols listed - `attr_writer`: Create setters for the symbols listed diff --git a/concepts/loops/about.md b/concepts/loops/about.md index e53ff28ac4..a0bd2353e3 100644 --- a/concepts/loops/about.md +++ b/concepts/loops/about.md @@ -39,4 +39,5 @@ def self.years_before_desired_balance(current_balance, desired_balance) end ``` -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. +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. diff --git a/concepts/modules/about.md b/concepts/modules/about.md index a23ede2ac3..b8ed3bd6dc 100644 --- a/concepts/modules/about.md +++ b/concepts/modules/about.md @@ -4,7 +4,8 @@ Some times you don't need the overhead of creating an object with state. In these cases, a `module` can be used. A module is very similar to a class (in fact, `Module` is `Classes` parent in the object hierarchy) - the main difference being that rather than using instance methods, we use class methods. -Class methods start with `self.` and are directly called on a module. +Class methods start with `self.` and are directly called on a module. + For example: ```ruby diff --git a/concepts/modules/introduction.md b/concepts/modules/introduction.md index ac03f348a8..322d279c36 100644 --- a/concepts/modules/introduction.md +++ b/concepts/modules/introduction.md @@ -4,7 +4,8 @@ Some times you don't need the overhead of creating an object with state. In these cases, a `module` can be used. A module is very similar to a class (in fact, `Module` is an ancestor of `Class` in the object hierarchy) - the main difference being that rather than using instance methods, we use class methods. -Class methods start with `self.` and are directly called on a module. +Class methods start with `self.` and are directly called on a module. + For example: ```ruby diff --git a/concepts/multiple-assignment-and-decomposition/about.md b/concepts/multiple-assignment-and-decomposition/about.md index a62c8204cc..b44449401a 100644 --- a/concepts/multiple-assignment-and-decomposition/about.md +++ b/concepts/multiple-assignment-and-decomposition/about.md @@ -269,8 +269,7 @@ This will pack all **key**/**value** pairs from one hash into another hash, or c ### Composition with method parameters When you create a method that accepts an arbitrary number of arguments, you can use [`*arguments`][arguments] or [`**keyword_arguments`][keyword arguments] in the method definition. -`*arguments` is used to pack an arbitrary number of positional (non-keyworded) arguments and -`**keyword_arguments` is used to pack an arbitrary number of keyword arguments. +`*arguments` is used to pack an arbitrary number of positional (non-keyworded) arguments and `**keyword_arguments` is used to pack an arbitrary number of keyword arguments. Usage of `*arguments`: diff --git a/concepts/nil/about.md b/concepts/nil/about.md index 991ee520ab..59391b71bf 100644 --- a/concepts/nil/about.md +++ b/concepts/nil/about.md @@ -1,6 +1,8 @@ # About -[Nil][nil-dictionary] is an English word meaning "nothing" or "zero". In Ruby, `nil` is an object which is used to express the _absence_ of a value. In other programming languages, `null` or `none` values may play a similar role. +[Nil][nil-dictionary] is an English word meaning "nothing" or "zero". +In Ruby, `nil` is an object which is used to express the _absence_ of a value. +In other programming languages, `null` or `none` values may play a similar role. ```ruby # I do not have a favorite color diff --git a/concepts/nil/introduction.md b/concepts/nil/introduction.md index f4dfd2c0e6..61cd2a9469 100644 --- a/concepts/nil/introduction.md +++ b/concepts/nil/introduction.md @@ -1,7 +1,8 @@ # Introduction - -[Nil][nil-dictionary] is an English word meaning "nothing" or "zero". In Ruby, `nil` is used to express the _absence_ of an object. In other programming languages, `null` or `none` values may play a similar role. +[Nil][nil-dictionary] is an English word meaning "nothing" or "zero". +In Ruby, `nil` is used to express the _absence_ of an object. +In other programming languages, `null` or `none` values may play a similar role. ```ruby # I do not have a favorite color diff --git a/concepts/numbers/about.md b/concepts/numbers/about.md index 40e5643a33..ce6b8e26b0 100644 --- a/concepts/numbers/about.md +++ b/concepts/numbers/about.md @@ -12,11 +12,14 @@ b.class #=> Float ``` -- Arithmetic is done using the basic [arithmetic operators][arithmetic-operators] (`+`, `-`, `*`, `/`). Numbers can be compared using the standard [comparison operators][comparison-operators]. +- Arithmetic is done using the basic [arithmetic operators][arithmetic-operators] (`+`, `-`, `*`, `/`). + Numbers can be compared using the standard [comparison operators][comparison-operators]. - Basic arithmetic operations between instances of `Integer`, will always result in an instance of `Integer`. - Basic arithmetic operations between instances of `Float` will result in other instances of `Float`. - Basic arithmetic operations between instances of `Integer` and instances of `Float` will result in instances of `Float`. -- The `Float` and `Integer` classes have methods that will coerce values from one to the other. `Integer` numbers are precise to a whole unit, while `Float` has precision that is fractional to an whole number. This means that coercing a float to an integer may result in loss of precision. +- The `Float` and `Integer` classes have methods that will coerce values from one to the other. + `Integer` numbers are precise to a whole unit, while `Float` has precision that is fractional to an whole number. + This means that coercing a float to an integer may result in loss of precision. ```ruby 4.9.to_i @@ -74,7 +77,8 @@ else end ``` -The same problem can sometimes be solved using different types of conditional statements, sometimes one might be more suited for the problem than the other. It's a good idea to stop for a moment and also consider the other two options when using any of the three conditional statements. +The same problem can sometimes be solved using different types of conditional statements, sometimes one might be more suited for the problem than the other. +It's a good idea to stop for a moment and also consider the other two options when using any of the three conditional statements. [arithmetic-operators]: https://www.tutorialspoint.com/ruby/ruby_operators.htm [comparison-operators]: https://www.w3resource.com/ruby/ruby-comparison-operators.php diff --git a/concepts/numbers/introduction.md b/concepts/numbers/introduction.md index 29c31fb608..be25ad923f 100644 --- a/concepts/numbers/introduction.md +++ b/concepts/numbers/introduction.md @@ -2,9 +2,13 @@ Two common types of numbers in Ruby are: -- Integers: numbers with no digits behind the decimal separator (whole numbers). Examples are `-6`, `0`, `1`, `25`, `976` and `500_000`. -- Floating-point numbers: numbers with zero or more digits behind the decimal separator. Examples are `-2.4`, `0.1`, `3.14`, `16.984025` and `1024.0`, (they also can use the `_` as a separator for readability as shown above such as `1_024.0`). +- Integers: numbers with no digits behind the decimal separator (whole numbers). + Examples are `-6`, `0`, `1`, `25`, `976` and `500_000`. +- Floating-point numbers: numbers with zero or more digits behind the decimal separator. + Examples are `-2.4`, `0.1`, `3.14`, `16.984025` and `1024.0`, (they also can use the `_` as a separator for readability as shown above such as `1_024.0`). They are implemented through the `Integer` and `Float` classes. -The `Float` and `Integer` classes have methods that will coerce values from one to the other. `Integer` numbers are precise to a whole unit, while `Float` has precision that is fractional to a whole number. +The `Float` and `Integer` classes have methods that will coerce values from one to the other. +`Integer` numbers are precise to a whole unit, while `Float` has precision that is fractional to a whole number. + diff --git a/concepts/ostruct/about.md b/concepts/ostruct/about.md index e262b94eed..41e512c906 100644 --- a/concepts/ostruct/about.md +++ b/concepts/ostruct/about.md @@ -3,7 +3,8 @@ Ruby comes with a Standard Library (often shortened to "stdlib") - a collection of classes for working with things such as dates, json, and networking. It also provides some useful functionality for making your code easier to work with. -`OpenStruct` is part of the Standard Library and allows you to easily create an object from a `Hash`. Rather than having to access using `Hash` keys, `OpenStruct` instead allows us to use methods to access and set values. +`OpenStruct` is part of the Standard Library and allows you to easily create an object from a `Hash`. +Rather than having to access using `Hash` keys, `OpenStruct` instead allows us to use methods to access and set values. When using classes from the Standard Library, or any other library, you need to require that class using the `require` method. @@ -27,7 +28,9 @@ person.age #=> 35 ``` -One bonus advantage of this is that you can take advantage of a shortcut when using block syntax. In situations where a block calls a single method, you can replace the block with `&:` followed by the method name. For example, these two lines are synonymous: +One bonus advantage of this is that you can take advantage of a shortcut when using block syntax. +In situations where a block calls a single method, you can replace the block with `&:` followed by the method name. +For example, these two lines are synonymous: ```ruby people.sum { |person| person.age } diff --git a/concepts/ostruct/introduction.md b/concepts/ostruct/introduction.md index a094cdff03..7ef44f49d1 100644 --- a/concepts/ostruct/introduction.md +++ b/concepts/ostruct/introduction.md @@ -3,7 +3,8 @@ Ruby comes with a Standard Library (often shortened to "stdlib") - a collection of classes for working with things such as dates, json, and networking. It also provides some useful functionality for making your code easier to work with. -`OpenStruct` is part of the Standard Library and allows you to easily create an object from a `Hash`. Rather than having to access using `Hash` keys, `OpenStruct` instead allows us to use methods to access and set values. +`OpenStruct` is part of the Standard Library and allows you to easily create an object from a `Hash`. +Rather than having to access using `Hash` keys, `OpenStruct` instead allows us to use methods to access and set values. When using classes from the Standard Library, or any other library, you need to require that class using the `require` method. @@ -27,7 +28,9 @@ person.age #=> 35 ``` -One bonus advantage of this is that you can take advantage of a shortcut when using block syntax. In situations where a block calls a single method, you can replace the block with `&:` followed by the method name. For example, these two lines are synonymous: +One bonus advantage of this is that you can take advantage of a shortcut when using block syntax. +In situations where a block calls a single method, you can replace the block with `&:` followed by the method name. +For example, these two lines are synonymous: ```ruby people.sum { |person| person.age } diff --git a/concepts/ranges/about.md b/concepts/ranges/about.md index ac61e0a899..4a6e3e5f88 100644 --- a/concepts/ranges/about.md +++ b/concepts/ranges/about.md @@ -88,7 +88,7 @@ Its behavior can be a bit unexpected when using certain strings, so use it with ## Custom objects in ranges ~~~~exercism/advanced -Ruby allows you to use custom objects in ranges. +Ruby allows you to use custom objects in ranges. The requirement for this is that the object implements the following: - include the `Comparable` module @@ -100,9 +100,9 @@ These methods make it so that the range can iterate over the object and compare ```ruby class Foo include Comparable - + attr_reader :value - + def initialize(value) @value = value end @@ -119,6 +119,7 @@ end (Foo.new(1)..Foo.new(5)) # => #, #, #, #, # ``` + ~~~~ [range]: https://docs.ruby-lang.org/en/master/Range.html diff --git a/concepts/strings/about.md b/concepts/strings/about.md index 323925bf3e..99244bc775 100644 --- a/concepts/strings/about.md +++ b/concepts/strings/about.md @@ -1,8 +1,10 @@ # About -The key thing to remember about Ruby strings is that they are objects that you call methods on. You can find all the methods in the [Ruby docs][ruby-doc.org-string] +The key thing to remember about Ruby strings is that they are objects that you call methods on. +You can find all the methods in the [Ruby docs][ruby-doc.org-string] -It's also worth knowing that strings can be created using single quotes (`'`) or double quotes (`"`). Single-quoted strings don't process ASCII escape codes(\n, \t etc.), and they don't do [string interpolation][ruby-for-beginners.rubymonstas.org-interpolation] while double-quoted does both. +It's also worth knowing that strings can be created using single quotes (`'`) or double quotes (`"`). +Single-quoted strings don't process ASCII escape codes(\n, \t etc.), and they don't do [string interpolation][ruby-for-beginners.rubymonstas.org-interpolation] while double-quoted does both. You can also create strings using the [heredoc syntax][ruby-heredoc] or using the `%q` and `%Q` helpers. diff --git a/concepts/strings/introduction.md b/concepts/strings/introduction.md index 94ddba0f50..e389a71c71 100644 --- a/concepts/strings/introduction.md +++ b/concepts/strings/introduction.md @@ -1,3 +1,4 @@ # Introduction -A `String` in Ruby is an object that holds and manipulates an arbitrary sequence of bytes, typically representing characters. Strings are manipulated by calling the string's methods. +A `String` in Ruby is an object that holds and manipulates an arbitrary sequence of bytes, typically representing characters. +Strings are manipulated by calling the string's methods. diff --git a/concepts/ternary-operator/about.md b/concepts/ternary-operator/about.md index 9eac49f588..7e53ef6846 100644 --- a/concepts/ternary-operator/about.md +++ b/concepts/ternary-operator/about.md @@ -1,6 +1,6 @@ # The ternary operator -A ternary conditional is a shorter way of writing simple `if/else` statements. +A ternary conditional is a shorter way of writing simple `if/else` statements. If an `if/else` statement contains only two branches, one for when the condition is true and one for when it is false, it can be re-written as a ternary conditional. Ternaries use a combination of the `?` and `:` symbols to split up a conditional: @@ -8,7 +8,7 @@ Ternaries use a combination of the `?` and `:` symbols to split up a conditional condition ? true_branch : false_branch ``` -The code on the left side of the `?` is the condition and the code on the right contains the two possible branches, separated by the `:`. +The code on the left side of the `?` is the condition and the code on the right contains the two possible branches, separated by the `:`. If the condition is _true_, the code on the _left_ side of the `:` is executed. If the condition is _false_, then the code on the _right_ of the `:` gets executed. diff --git a/concepts/ternary-operator/introduction.md b/concepts/ternary-operator/introduction.md index 9eac49f588..7e53ef6846 100644 --- a/concepts/ternary-operator/introduction.md +++ b/concepts/ternary-operator/introduction.md @@ -1,6 +1,6 @@ # The ternary operator -A ternary conditional is a shorter way of writing simple `if/else` statements. +A ternary conditional is a shorter way of writing simple `if/else` statements. If an `if/else` statement contains only two branches, one for when the condition is true and one for when it is false, it can be re-written as a ternary conditional. Ternaries use a combination of the `?` and `:` symbols to split up a conditional: @@ -8,7 +8,7 @@ Ternaries use a combination of the `?` and `:` symbols to split up a conditional condition ? true_branch : false_branch ``` -The code on the left side of the `?` is the condition and the code on the right contains the two possible branches, separated by the `:`. +The code on the left side of the `?` is the condition and the code on the right contains the two possible branches, separated by the `:`. If the condition is _true_, the code on the _left_ side of the `:` is executed. If the condition is _false_, then the code on the _right_ of the `:` gets executed.