# Method Name: Straightforward, or Accurate?

**URL:** <https://metaruby.com/t/method-name-straightforward-or-accurate/1545>\
**Category:** Ruby Questions\
**Created:** [February 24, 2018, 12:19am UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545 "2018-02-24T00:19:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BurdetteLamar](https://metaruby.com/user_avatar/metaruby.com/burdettelamar/32/758_2.png) [@BurdetteLamar](https://metaruby.com/u/BurdetteLamar)\
**Post date:** [February 24, 2018, 12:19am UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545/1 "2018-02-24T00:19:15Z")

</div>

I am working on a Ruby logger. (Yes, yet another logger! But this one is _different_. Really!).

For logging an array (or array-like object), the method could be either `Log#put_array` or `Log#put_each_with_index`.

The former seems more straightforward, but the latter describes more closely what the method actually does.

Similarly, for logging a hash-like object, the method could be either `Log#put_hash` or `Log#put_each_pair`.

What’s the right thing in these cases, do you think?

---

<div class="post-metadata">

**Author:** ![danielpclark](https://metaruby.com/user_avatar/metaruby.com/danielpclark/32/823_2.png) [@danielpclark](https://metaruby.com/u/danielpclark)\
**Post date:** [February 24, 2018, 12:36am UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545/2 "2018-02-24T00:36:59Z")

</div>

The more descriptive methods make more sense.

---

<div class="post-metadata">

**Author:** ![BurdetteLamar](https://metaruby.com/user_avatar/metaruby.com/burdettelamar/32/758_2.png) [@BurdetteLamar](https://metaruby.com/u/BurdetteLamar)\
**Post date:** [February 26, 2018, 8:19pm UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545/3 "2018-02-26T20:19:14Z")

</div>

Ended up naming them more descriptively (log#put\_each\_with\_Index), then aliasing as log#put\_array.

Duh.

---

<div class="post-metadata">

**Author:** ![danielpclark](https://metaruby.com/user_avatar/metaruby.com/danielpclark/32/823_2.png) [@danielpclark](https://metaruby.com/u/danielpclark)\
**Post date:** [March 2, 2018, 11:53am UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545/4 "2018-03-02T11:53:22Z")

</div>

If you’d like you can put the printing behavior in a lambda and pass it to `each.with_index`.

```ruby
put = -> item, index=nil { puts "#{item} #{index}" }

[1,2,3].each.with_index(&put)
# 1 0
# 2 1
# 3 2
# => [1, 2, 3]

[1,2,3].each(&put)
# 1 
# 2 
# 3 
# => [1, 2, 3]

```

---

<div class="post-metadata">

**Author:** ![BurdetteLamar](https://metaruby.com/user_avatar/metaruby.com/burdettelamar/32/758_2.png) [@BurdetteLamar](https://metaruby.com/u/BurdetteLamar)\
**Post date:** [March 2, 2018, 3:12pm UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545/5 "2018-03-02T15:12:30Z")

</div>

Most interesting post, Daniel, for which Thanks!

---

<div class="post-metadata">

**Author:** ![PikachuEXE](https://metaruby.com/user_avatar/metaruby.com/pikachuexe/32/854_2.png) [@PikachuEXE](https://metaruby.com/u/PikachuEXE)\
**Post date:** [March 5, 2018, 3:50am UTC](https://metaruby.com/t/method-name-straightforward-or-accurate/1545/6 "2018-03-05T03:50:26Z")

</div>

I prefer being accurate  
If enough people request for an alias, then add it maybe

Remember the no. of times of code reading is usually more than code writing :004:
