# Eternity Async Tutoring

**URL:** <https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932>\
**Category:** Tutoring\
**Created:** [April 17, 2024, 11:22pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932 "2024-04-17T23:22:52Z")\
**Posts on this page:** 20\
**Page:** 42

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [February 25, 2025, 4:10am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/822 "2025-02-25T04:10:08Z")

</div>

Since I’m a bit stuck/lost I decided to go back and read some of the stuff you posted about Ruby.

> [@Elliot](#):
>
> Ruby is an object oriented programming language. That’s a design pattern which is commonly used throughout. An “object” is a complex data type that groups together variables and functions. This helps organize functions in two ways. First, it separates functions into groups instead of there being a single list of all functions that exist. Second, it groups functions together with relevant data.

Objects group together variables, things that can hold information, and functions, ways to manipulate the information. Objects have both? Hmm. Grouped, not combined?

It being object oriented helps organize functions into groups. So non-object oriented languages wouldn’t group functions.

> [@Elliot](#):
>
> A “class” is the name for a type or category of object. Then one or more objects of that type can be made. E.g. Integer and String are classes in Ruby, and you can have multiple “instances” of them: 1, 2, 3, “hi”, “bye”, “string”, etc.

category/type of object = class. one or more objects of that class can be made. integer and string are classes. instances are objects?

> [@Elliot](#):
>
> Every object instance has some data (in this case, what number it is, or what characters are in the string) and some functions. In object oriented programming, functions are commonly called “methods” and are called with a dot syntax.

functions are the same as methods

2,upto(4) ← . syntax

> [@Elliot](#):
>
> Objects also help with reusing code. If you’re writing chess software, you’ll deal with 32 pieces and 64 squares. Instead of defining each one individually, you can make a piece class and a square class and use each class multiple times. You can also have sub-classes (like a knight or queen) which have the code for pieces plus additional customizations. If you’re making poker software, you can have a card class with variables for the suit and the number instead of writing separate code for all 52 cards.

we making poker software? ;o

you can make classes? hmm. im getting a bit lost on what classes actually are then

> [@Elliot](#):
>
> Object functions can take inputs.

Whats an object function?

> [@Elliot](#):
>
> Function calls can be chained together. `3.-(4).+(5)` Guess what this will output then run it and see.

Never did this I think. Woops. 3 subtract 4 add 5? so 4:

 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/5/5638469af91673dcfe1ca75b18f39e6577c59f3c.png)

Hmm. To clarify: are functions and methods the same things when it comes to Ruby?

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [February 25, 2025, 4:18am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/823 "2025-02-25T04:18:54Z")

</div>

> [@Elliot](#):
>
> Run it with your own test data in IRB, e.g.:
> 
> `hand_to_ranks(%w[AH AD 5H 3S 2C])`

Am I misunderstanding something here? So here’s my code (I removed the other functions that you told me to make for now because I wasn’t doing anything with them yet):

```auto
cards = Array.new
suits = ["S","C","D","H"]
letters = ["A","T","J","Q","K"]

suits.each do |a|
  2.upto(9) do |n|
  cards << "#{n}#{a}"
  end
  letters.each do |l|
  cards << "#{l}#{a}"
  end
end

deck = cards.shuffle

hand = deck.slice!(0..4)

def hand_to_ranks(hand)
  ranks=Array.new

  hand.each do |n|
    ranks<<n[0]
  end
  ranks
end

hand_to_ranks(hand)

```

So hand\_to\_ranks(hand) returns value in irb:  
 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/a/acbef1f73b6eab2dc3591c0b784918cc366fb750.png)

I just replaced the hand in hand\_to\_rank(hand) with the array you provided. So  
hand\_to\_ranks(%w[AH AD 5H 3S 2C]).:

![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/6/6f40841f70fdd20572832319d6a1827d4c5b9b24.png)

oh it works, nvm then

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [February 25, 2025, 5:51pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/824 "2025-02-25T17:51:25Z")

</div>

You can simplify your `hand_to_ranks` function using `map` instead of `each`.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [February 25, 2025, 5:56pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/825 "2025-02-25T17:56:04Z")

</div>

> [@Eternity](#):
>
> It being object oriented helps organize functions into groups. So non-object oriented languages wouldn’t group functions.

Sometimes they group functions in other ways like namespaces.

> [@Eternity](#):
>
> you can make classes? hmm. im getting a bit lost on what classes actually are then

Yes you can make custom classes and also make changes to built-in classes.

> [@Eternity](#):
>
> Whats an object function?

A function that’s built into an object.

> [@Eternity](#):
>
> To clarify: are functions and methods the same things when it comes to Ruby?

yes. technically ruby doesn’t have pure functions like regular math. it’s fully object-oriented. you can make some stuff look like regular functions but there’s an implied object.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [February 25, 2025, 7:01pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/826 "2025-02-25T19:01:31Z")

</div>

> [@Elliot](#):
>
> A function that’s built into an object.

> [@Elliot](#):
>
> yes. technically ruby doesn’t have pure functions like regular math. it’s fully object-oriented. you can make some stuff look like regular functions but there’s an implied object.

Ok. So all functions/methods in ruby are object functions. All functions are object functions which are functions that are built into an object. Ruby only has objects. Some stuff may look like a regular function but there’s an implied object. Like puts being self.puts.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [February 25, 2025, 7:06pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/827 "2025-02-25T19:06:46Z")

</div>

> [@Elliot](#):
>
> You can simplify your `hand_to_ranks` function using `map` instead of `each`.

```auto
def hand_to_ranks(hand)
  ranks = hand.map {|n| n[0]}
end

```

![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/b/b842c005e77512503fb0d022e5b4152b04f3e4f1.png)

neat

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [February 25, 2025, 10:30pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/828 "2025-02-25T22:30:09Z")

</div>

Ran into this quote from [Objectively Speaking: Ayn Rand Interviewed: Podritske, Marlene, Schwartz, Peter: 9780739131954: Amazon.com: Books](https://www.amazon.com/Objectively-Speaking-Ayn-Rand-Interviewed/dp/0739131958) while doing reviews:

> Nothing but his own intelligence and integrity. The issue here is the same as in science, where man is also not guaranteed against error. Man has to arrive at knowledge by a rational process. And that process is not infallible. Man can make errors, and so he has rules by which he can trace his errors. The science that provides these rules is logic, which is the art of non-contradictory identification. If a man makes an error in his reasoning, sooner or later it will lead him to a contradiction. By that means, he can know that he has made a mistake, can retrace the steps of his reasoning process and can unearth his error.

I think I highlighted it cause of the stuff about being fallible.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [February 26, 2025, 7:56pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/829 "2025-02-26T19:56:39Z")

</div>

I’m confused about something:

```auto
def hand_to_ranks(hand)
  rank = hand.map {|n| n[0]}
end

def rank_to_number(rank)
  # J = 11, Q = 12, K = 13, A = 14. For now we'll ignore how A can sometimes be 1.
puts rank.class
end

```

It says rank is undefined. Is it because its used in a definition of a function “hand\_to\_ranks”. I put the puts command so I could see some output in the IDE, but I also did it in irb (without puts) to see the return value of rank:

 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/c/cb25a6c0bd3b315d13cb414c5063cd0dfd114a94.png)

Oh yeah. class doesn’t have anything to do with my solution to this part of the programming assignment. I was testing out things I thought maybe would work and I noticed rank kept returning undefined so I just chose to run something simple to double check.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [February 26, 2025, 9:04pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/830 "2025-02-26T21:04:05Z")

</div>

Inputs to functions are only available inside their function.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [March 2, 2025, 6:00pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/831 "2025-03-02T18:00:25Z")

</div>

> [@Elliot](#):
>
> Inputs to functions are only available inside their function.

Ok. I’m a bit confused with how that all works then. Just to check the four functions you gave to me to work out are meant to actually be used, right? They’re not just like different parts I need to figure out?

I kinda am confused with the whole function thing. I did find a way to get to rank\_to\_numbers but I did it outside of my function.

```auto
cards = Array.new
suits = ["S","C","D","H"]
letters = ["A","T","J","Q","K"]

suits.each do |a|
  2.upto(9) do |n|
  cards << "#{n}#{a}"
  end
  letters.each do |l|
  cards << "#{l}#{a}"
  end
end

deck = cards.shuffle

hand = deck.slice!(0..4)

rank = hand.map {|n| n[0]}

rank_to_number = {"A" => 14, "J"=> 11, "Q"=>12, "K"=>13,"T"=>10, "2"=>2, "3"=>3, "4"=>4, "5"=>5 , "6"=>6, "7"=>7, "8"=>8, "9"=>9}

number = Array.new

rank.each do |n|
  number << rank_to_number[n]
end

```

I know this isn’t exactly what I was supposed to but I had an idea for rank\_to\_number that I thought could work, wasn’t working with the function stuff, and so I just tried it out of the function last night. I spent a few minutes trying to do it with function but its not working. Hmm. In the assignment you gave for rank\_to\_number you didn’t say an array for the numbers so there’s that too.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [March 2, 2025, 6:20pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/832 "2025-03-02T18:20:18Z")

</div>

The general concept of a function is it’s a reusable chunk of code which takes some inputs and then calculates an output using only the input data. Functions are important to understand and be able to use. (Most programming languages allow impure functions which can interact with external data. This is widely used but generally only done in specific, organized ways.)

Yes the functions are meant to be used.

If you show your problem using a rank\_to\_number function I could comment more.

> [@Eternity](#):
>
> In the assignment you gave for rank\_to\_number you didn’t say an array for the numbers so there’s that too.

I don’t know what this means.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [March 2, 2025, 6:30pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/833 "2025-03-02T18:30:19Z")

</div>

> [@Elliot](#):
>
> I don’t know what this means.

Ahh when doing rank\_to\_numbers I don’t know if it should be an array. You didn’t mention it in your comment when giving me the functions to work through:

```auto
def rank_to_number(rank)
  # J = 11, Q = 12, K = 13, A = 14. For now we'll ignore how A can sometimes be 1.
  # code
end

```

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [March 2, 2025, 6:31pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/834 "2025-03-02T18:31:47Z")

</div>

You didn’t know if what should be an array?

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [March 2, 2025, 6:35pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/835 "2025-03-02T18:35:38Z")

</div>

> [@Elliot](#):
>
> You didn’t know if what should be an array?

Hmm. I guess: should the return value of that function be an array.

Or, I guess, what am I trying to do in this section? What I think I’m trying to do is here turn my array that I made earlier that has the ranks into an array that has the number value of those ranks.

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [March 2, 2025, 6:38pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/836 "2025-03-02T18:38:50Z")

</div>

OK, I see. `def rank_to_number(rank)` is self-explanatory to me but you’re not familiar with naming conventions.

X\_to\_Y indicates a conversion function that turns X (the input) to Y (the output).

If the input or output were an array, I’d use a plural noun instead of a singular noun to indicate that.

It’s often best to make helper functions that do small, individual tasks. If you need to convert multiple things, you can call the function multiple times, e.g. using `Array#map`.

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [March 3, 2025, 4:41am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/837 "2025-03-03T04:41:03Z")

</div>

So I did this:

```auto
def rank_to_number(rank)
  # J = 11, Q = 12, K = 13, A = 14. For now we'll ignore how A can sometimes be 1.
  rtn = {"A" => 14, "J"=> 11, "Q"=>12, "K"=>13,"T"=>10, "2"=>2, "3"=>3, "4"=>4, "5"=>5 , "6"=>6, "7"=>7, "8"=>8, "9"=>9}
  rtn[rank]
end

```

Seems to work in irb, if I understand what the goal of this code was,:  
 ![image](https://discuss.criticalfallibilism.com/uploads/default/original/2X/4/4cccaffedf23176a16357ab2be1308532870babb.png)

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [March 3, 2025, 4:44am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/838 "2025-03-03T04:44:58Z")

</div>

Oh yeah I made a feature request for the quoting issue:

> **[Improving quoting quote accuracy](https://meta.discourse.org/t/improving-quoting-quote-accuracy/355053)**
>
> Hello. I’m a relatively new discourse user. Here’s a thread I created earlier about the issue I was having: I don’t know if this is a bug or not. The feature I’m asking for is keeping quote levels accurate when quoting partial text from...

---

<div class="post-metadata">

**Author:** ![Eternity](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/eternity/32/5930_2.png) [@Eternity](https://discuss.criticalfallibilism.com/u/Eternity)\
**Post date:** [March 3, 2025, 5:16am UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/839 "2025-03-03T05:16:36Z")

</div>

For

```auto
def find_all_pairs(hand)
  # returns an empty array for no pairs, otherwise an array with the ranks of the pairs found. cards can't be reused in multiple pairs, so 3 jacks form one pair and 4 jacks form 2 pairs.
  hand_ranks = hand_to_ranks(hand)
  # more code
end

```

I can’t find anything that I think would be helpful. My plan is just to use a bunch of if statements. Something like “if hand[0] = hand[1]” and do that to check for every pair. I’m going to try this way tomorrow to see if it even works but any other suggestion?

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [March 3, 2025, 3:00pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/840 "2025-03-03T15:00:47Z")

</div>

That will be a hassle and wouldn’t scale. What if a hand had 10 or 1000 cards?

So let’s break the problem down into smaller parts.

Suppose you want to know whether the first card in the hand pairs with any other card in the hand? How could you figure that out using a loop or some other method where the number of lines of code doesn’t go up as the hand gets larger?

---

<div class="post-metadata">

**Author:** ![Elliot](https://discuss.criticalfallibilism.com/user_avatar/discuss.criticalfallibilism.com/elliot/32/14_2.png) [@Elliot](https://discuss.criticalfallibilism.com/u/Elliot)\
**Post date:** [March 3, 2025, 3:22pm UTC](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932/841 "2025-03-03T15:22:02Z")

</div>

I joined in [Improving quoting quote accuracy - #9 by curi - Feature - Discourse Meta](https://meta.discourse.org/t/improving-quoting-quote-accuracy/355053/9?u=curi)

[Previous page](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932.md?page=41)

[Next page](https://discuss.criticalfallibilism.com/t/eternity-async-tutoring/1932.md?page=43)
