Skip to content

Syntax improvements and other useful methods for ruby

License

Notifications You must be signed in to change notification settings

jonahx/pretty_ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9dc2281 · Sep 25, 2019

History

6 Commits
Sep 23, 2019
Sep 23, 2019
Jul 23, 2018
Apr 11, 2019
Jul 23, 2018
Jul 23, 2018

Repository files navigation

996.icu

What does it do?

Adds helpful methods and new syntax to existing methods to improve readability and expressiveness.

Examples will explain best:

require 'pretty_ruby'
using PrettyRuby

# map methods that require arguments
arr = [ ['a', 'b', 'c'], ['d', 'e', 'f'] ]
arr.map(:join, '-') #=> [ 'a-b-c', 'd-e-f' ]

# use >> as a pipeline operator
arr = 'hello'.chars
arr.map(:next >> :upcase).join('-') #=> "I-F-M-M-P"

# support negative take and drop
arr = [1, 2, 3, 4, 5]
arr.take(-2) # => [4, 5]
arr.drop(-2) # => [1, 2, 3]

# add tail / init
arr.tail # => [2, 3, 4, 5]
arr.init # => [1, 2, 3, 4]

# scan without arguments
'abcde'.scan #=> ["a", "ab", "abc", "abcd", "abcde"]

# scan with arguments
arr = [1, 2, 3, 4, 5]
arr.scan(:+) #=> [1, 3, 6, 10, 15]
arr.scan(:*) #=> [1, 2, 6, 24, 120]

TODO

Document other features

Go through the remaining Enumerable and Array methods to support the new syntax where relevant.

  • count
  • detect
  • find_index
  • find_all
  • select
  • reject
  • collect
  • map
  • flat_map
  • collect_concat
  • inject
  • reduce
  • partition
  • group_by
  • first
  • all?
  • any?
  • one?
  • none?
  • minmax
  • minmax_by
  • member?
  • each_with_index
  • reverse_each
  • each_entry
  • each_slice
  • each_cons
  • each_with_object
  • zip
  • take
  • take_while
  • drop
  • drop_while
  • cycle
  • chunk
  • slice_before
  • slice_after
  • slice_when
  • chunk_while
  • sum
  • uniq

About

Syntax improvements and other useful methods for ruby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages