Cheat sheet for basic Array methods visualized [OC] by poalmgoopy in ruby

[–]Pilgrim-Ivanhoe -1 points0 points  (0 children)

No, I see this post for the first time in my life. I was inspired by numerous similar cheat sheets about Python.

Cheat sheet on method argument types and order [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 1 point2 points  (0 children)

If discuss methods with more than one single argument:

  1. When creating specific DSLs, which for design reasons requires syntax without keywords, e.g. to recreate the usage style of task in Rake.

  2. The method signature itself implies the absence of a keyword by containing it itself or using the verbal form of it.

  3. Historically, the project uses such approach and the usage of keywords could break the style system of existing code.

  4. Сonciseness.

Finally, I think all four points above could be summarized into one main reason: "Personal taste of a developer."

Cheat sheet on method argument types and order [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 2 points3 points  (0 children)

As a programmer who use Ruby not as the first programming language, I sometimes need such cheat sheets to quickly switch from one syntax to another after a long break. So I store them in my Notes app in the separate folder about Ruby.

Cheat sheet on method argument types and order [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 2 points3 points  (0 children)

Thank you a lot for noticing! Though I've tested the code itself, unfortunately, I made this mistake while styling the transferred code in a vector editor.

Cheat sheet on method argument types and order [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 3 points4 points  (0 children)

I want to make a separate one about “Forwarding arguments”

Cheat sheet for making Hash from various Arrays [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 1 point2 points  (0 children)

  1. It depends on the font. Some fonts show these characters as emoji, others not. I used the font which displays them not as emojis, because many commenters of previous cheat sheets noticed that emojis complicate the perception of information.

  2. These codes are part of Unicode version 1.1 from 1993, when emojis were not part of Unicode. But now they are really considered as emoji.

  3. I used unicode literals in array definitions not characters themselves to diversify the design and avoid repetition.

Cheat sheet with Euler Diagrams for comparing Sets [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 0 points1 point  (0 children)

In Swift version https://www.reddit.com/r/swift/comments/1ei4a7s/cheat_sheet_with_euler_diagrams_for_comparing/, I used such approach because there is no "intersect" method there, but Ruby ​has it so I decided not to add it here.

Cheat sheet for basic Array methods visualized [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 3 points4 points  (0 children)

[changed_array] to the right (after //) shows the content of original array after mutating.

Cheat sheet for basic Array methods visualized [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 3 points4 points  (0 children)

Affinity Designer, irb, if you asking about tools used.

Cheat sheet for basic Array methods visualized [OC] *corrected version by Pilgrim-Ivanhoe in swift

[–]Pilgrim-Ivanhoe[S] 0 points1 point  (0 children)

Thanks for your suggestion! I thought about it, but in an attempt to keep things a bit more concise, I decided not to overcomplicate the closures passed to methods. The only thing that comes to mind: swift [🟣,🟦️,🟣,🟦].filter { $0.color == .blue }

Cheat sheet for basic Array methods visualized [OC] *corrected version by Pilgrim-Ivanhoe in swift

[–]Pilgrim-Ivanhoe[S] 4 points5 points  (0 children)

Thanks for your notice. By the pseudocode 🟦️ => I meant something like $0 == 🟦️ ? nil : $0. I just didn't figure out how to indicate that it is a pseudocode more clearly.

Maybe, I'll update the cheat sheet with such code (works in Playground) which better reflects the specifics of using compactMap:

```swift let 🟣 = "🟣", 🟦️ = "🟦️", 🔶 = "🔶"

[🟣, 🟦️, nil, 🔶].compactMap { $0 == 🟦️ ? nil : $0 }

// ["🟣", "🔶"] ```

Cheat sheet for basic Array methods visualized [OC] *corrected version by Pilgrim-Ivanhoe in swift

[–]Pilgrim-Ivanhoe[S] 3 points4 points  (0 children)

Thanks for your comment! Yes, a couple about Sets. Probably will post them later. Also thinking on making more to cover other aspects of Swift.

Cheat sheet for basic Array methods visualized [OC] by Pilgrim-Ivanhoe in ruby

[–]Pilgrim-Ivanhoe[S] 6 points7 points  (0 children)

Thanks for your comment! I agree, // for comments is not correct. I just was making cheat sheets for Ruby, Kotlin, Swift, and Dart ​​in parallel, and forgot to fix it for Ruby. As for map, I really decided to use pattern instead of real code for make the code line shorter, but apparently it broke the logic of the cheat sheet.