0
11      (Ruby      Geek−− CafeToshio Maki(@Kirika_K2)
•
sampleclass InMemoryDirectory      def initialize            @elements = []      end     def add_element(new_element)     ...
•    •    •
•••
•   addElement    •   generate_index   def add_element(new_element)    @elements << new_element   end   def add_element(ne...
••
def add_element(new_element)    @elements << new_element   end    •   @elements    •   element_count    •   element
def generate_index    index = Element.new("index")    @elements.each{|e| index.add_text(e.name + "n") }    @elements << in...
class Element    attr_reader :name, :text    def initialize(name)        @name = name        @text = ""    end   def add_t...
•• element_count• element
require test/unitrequire in_memory_directoryclass InMemoryDirectoryTest < Test::Unit::TestCase       def setup           @...
$ ruby in_memory_directory_test.rbLoaded suite in_memory_directory_testStarted..Finished in 0.001858 seconds.2 tests, 2 as...
class InMemoryDirectory    def initialize        @elements = []    end   def add_element(new_element)       if @elements.e...
$ ruby in_memory_directory_test.rbLoaded suite in_memory_directory_testStarted.FFinished in 0.015029 seconds.  1) Failure:...
• add_element         Index        Element   2•
require test/unitrequire in_memory_directoryclass InMemoryDirectoryTest < Test::Unit::TestCase       def setup           @...
class InMemoryDirectory      def initialize            @elements = []      end     def add_element(new_element)          i...
•    ※•       static•                final, const•
••
Upcoming SlideShare
Loading in...5
×

レガシーコード改善ガイド

616

Published on

レガシーコード改善ガイド 11章

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
616
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript of "レガシーコード改善ガイド"

    1. 1. 11 (Ruby Geek−− CafeToshio Maki(@Kirika_K2)
    2. 2.
    3. 3. sampleclass InMemoryDirectory def initialize @elements = [] end def add_element(new_element) @elements << new_element end def generate_index index = Element.new("index") @elements.each{|e| index.add_text(e.name + "n") } @elements << index end def element_count @elements.length end def element(name) @elements.find{|e| e.name == name } endend
    4. 4. • • •
    5. 5. •••
    6. 6. • addElement • generate_index def add_element(new_element) @elements << new_element end def add_element(new_element) if @elements.empty? @elements << Element.new("index") end @elements << new_element element("index").add_text(new_element.name + "n") end
    7. 7. ••
    8. 8. def add_element(new_element) @elements << new_element end • @elements • element_count • element
    9. 9. def generate_index index = Element.new("index") @elements.each{|e| index.add_text(e.name + "n") } @elements << index end • @elements • element_count • element
    10. 10. class Element attr_reader :name, :text def initialize(name) @name = name @text = "" end def add_text(new_text) @text += new_text endend • add_text elements
    11. 11. •• element_count• element
    12. 12. require test/unitrequire in_memory_directoryclass InMemoryDirectoryTest < Test::Unit::TestCase def setup @dir = InMemoryDirectory.new @hoge_object = Element.new("hoge") @dir.add_element(@hoge_object) end def test_element_count assert_equal(1, @dir.element_count) end def test_element assert_equal(@hoge_object, @dir.element("hoge")) endend
    13. 13. $ ruby in_memory_directory_test.rbLoaded suite in_memory_directory_testStarted..Finished in 0.001858 seconds.2 tests, 2 assertions, 0 failures, 0 errors
    14. 14. class InMemoryDirectory def initialize @elements = [] end def add_element(new_element) if @elements.empty? @elements << Element.new("index") end @elements << new_element element("index").add_text(new_element.name + "n") end def element_count @elements.length end def element(name) @elements.find{|e| e.name == name } endend
    15. 15. $ ruby in_memory_directory_test.rbLoaded suite in_memory_directory_testStarted.FFinished in 0.015029 seconds. 1) Failure:test_element_count(InMemoryDirectoryTest)[in_memory_directory_test.rb:12]:<1> expected but was<2>.2 tests, 2 assertions, 1 failures, 0 errors
    16. 16. • add_element Index Element 2•
    17. 17. require test/unitrequire in_memory_directoryclass InMemoryDirectoryTest < Test::Unit::TestCase def setup @dir = InMemoryDirectory.new @hoge_object = Element.new("hoge") @dir.add_element(@hoge_object) @dir.generate_index end generate_index def test_element_count assert_equal(2, @dir.element_count) end def test_element assert_equal(@hoge_object, @dir.element("hoge")) endend
    18. 18. class InMemoryDirectory def initialize @elements = [] end def add_element(new_element) if @elements.empty? @elements << Element.new("index") end @elements << new_element element("index").add_text(new_element.name + "n") end def generate_index puts "WARNING: generate_index deplicated" end def element_count @elements.length end def element(name) @elements.find{|e| e.name == name } endend
    19. 19. • ※• static• final, const•
    20. 20. ••
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×