Refactor triangle.rb