Write ruby code to change ruby code

flyerhzm
September 19, 2014

Write ruby code to change ruby code

flyerhzm

September 19, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

46 slides
  1. Hey, let’s use rspec new syntax for project A Yes,

    sure, I love the rspec new syntax
  2. Hey, let’s use rspec new syntax for project C Oh,

    no, I don’t want to repeat it again
  3. Metric Tools • cane - fails your build if code

    quality thresholds are not met • reek - is a tool that examines Ruby classes, modules and methods and reports any code smells it finds. • rails_best_practices - is a tool to check the quality of rails code. • ……
  4. IDE

  5. IDE • can rename class / method / variable name

    • can extract methods • can ……
  6. Based on text Replace FactoryGirl.create with create ! $ sed

    -i '' 's/FactoryGirl.create/create/g' spec/**/*.rb
  7. How to use AST • ripper • ParseTree - https://github.com/seattlerb/parsetree

    • ruby_parser - https://github.com/seattlerb/ruby_parser • parser - https://github.com/whitequark/parser
  8. Synvert • Add useful attributes to AST nodes ! •

    Provide DSL to parse and rewrite code
  9. DSL • within_file / within_files • with_node / within_node •

    if_exist_node / unless_exist_node • append / insert / insert_after / replace_with / remove • ……
  10. Want more? • Fork and send pull request • Open

    issues on github • Hire us to refactor your project

More Decks by flyerhzm

Other Decks in Programming