https://github.com/andyw8/refactoring-ruby
https://github.com/andyw8/refactoring-ruby
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/andyw8/refactoring-ruby
- Owner: andyw8
- Created: 2018-12-02T15:43:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-19T13:43:57.000Z (over 6 years ago)
- Last Synced: 2025-01-05T19:13:03.157Z (5 months ago)
- Language: Ruby
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This repo contains examples from Chapter 1 of Refactoring (2nd edition),
converted to Ruby.You can view the commits individually to see each change. Some commits
have an corresponding explanation for Ruby-specific implementation details.A few small changes were needed:
Since the `Intl.NumberFormat` isn't available, I replaced it with a simplified
equivalent.In Ruby it's not possible directly assign a method to a variable, so I used a
lambda instead.To prevent a name clash for `result`, I made use of a block-local variable,
`lambda do |perf, play; result|`.I renamed the variables to use `snake_case` rather than `camelCase`.
# Testing
I added a simple integration test (using RSpec). If this was real code, I would
want more tests in place before I started to refactor.# Style
I'm generally aiming to follow Ruby Community Style, and I'm using RuboCop to
validate it. I disabled some rules which don't make sense considering this is an
exercise rather than real code.The book uses nested functions, which aren't available in Ruby, but can be
approximated using lambdas.