SlideShare a Scribd company logo
1 of 20
11
      (Ruby




      Geek−− Cafe
Toshio Maki(@Kirika_K2)
•
sample
class 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 }

     end
end
•

    •

    •
•
•
•
•   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
•


•
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 << index

   end

    •   @elements

    •   element_count
    •   element
class Element

    attr_reader :name, :text

    def initialize(name)

    
    @name = name

    
    @text = ""

    end


   def add_text(new_text)

   
    @text += new_text

   end
end



  • add_text               elements
•


• element_count
• element
require 'test/unit'
require 'in_memory_directory'

class 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"))

   
   end
end
$ ruby in_memory_directory_test.rb
Loaded suite in_memory_directory_test
Started
..
Finished in 0.001858 seconds.

2 tests, 2 assertions, 0 failures, 0 errors
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 }

   end
end
$ ruby in_memory_directory_test.rb
Loaded suite in_memory_directory_test
Started
.F
Finished 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
• add_element         Index
        Element   2

•
require 'test/unit'
require 'in_memory_directory'

class 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"))

   
    end
end
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 }

     end
end
•
    ※


•       static



•                final, const



•
•

•

More Related Content

What's hot

What's hot (19)

Hidden Docs in Angular
Hidden Docs in AngularHidden Docs in Angular
Hidden Docs in Angular
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Dive into React Performance
Dive into React PerformanceDive into React Performance
Dive into React Performance
 
Getting functional with elixir
Getting functional with elixirGetting functional with elixir
Getting functional with elixir
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Breaking the limits_of_page_objects
Breaking the limits_of_page_objectsBreaking the limits_of_page_objects
Breaking the limits_of_page_objects
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
codeigniter
codeignitercodeigniter
codeigniter
 
Object identification and its management
Object identification and its managementObject identification and its management
Object identification and its management
 
Schemadoc
SchemadocSchemadoc
Schemadoc
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
 
Sequel
SequelSequel
Sequel
 
Android training day 5
Android training day 5Android training day 5
Android training day 5
 
J Query
J QueryJ Query
J Query
 
Android training day 4
Android training day 4Android training day 4
Android training day 4
 
Php summary
Php summaryPhp summary
Php summary
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
 

Viewers also liked

Un dia a l'escola 1
Un dia a l'escola 1Un dia a l'escola 1
Un dia a l'escola 1
nurisaba
 
Race Horse Steroids
Race Horse SteroidsRace Horse Steroids
Race Horse Steroids
norrell44294
 
Southwest Ideas Investor Conference Presentation
Southwest Ideas Investor Conference PresentationSouthwest Ideas Investor Conference Presentation
Southwest Ideas Investor Conference Presentation
harleyebarnes
 
Marketing Agenzie di Viaggio
Marketing Agenzie di ViaggioMarketing Agenzie di Viaggio
Marketing Agenzie di Viaggio
T SOLUTIONS
 
Realtor.org listing presentation
Realtor.org listing presentationRealtor.org listing presentation
Realtor.org listing presentation
Michael Yurovsky
 
Photoshop designs presentation
Photoshop designs presentationPhotoshop designs presentation
Photoshop designs presentation
James Green
 
Revista palabra de pichikeche IV
Revista palabra de pichikeche IVRevista palabra de pichikeche IV
Revista palabra de pichikeche IV
komunidad
 

Viewers also liked (20)

Metaphor2
Metaphor2Metaphor2
Metaphor2
 
Tokyo at Child Scale
Tokyo at Child ScaleTokyo at Child Scale
Tokyo at Child Scale
 
Un dia a l'escola 1
Un dia a l'escola 1Un dia a l'escola 1
Un dia a l'escola 1
 
Race Horse Steroids
Race Horse SteroidsRace Horse Steroids
Race Horse Steroids
 
Ephesus2
Ephesus2Ephesus2
Ephesus2
 
Southwest Ideas Investor Conference Presentation
Southwest Ideas Investor Conference PresentationSouthwest Ideas Investor Conference Presentation
Southwest Ideas Investor Conference Presentation
 
Cultural Competency Research -- Jenn Chin's presentation
Cultural Competency Research -- Jenn Chin's presentationCultural Competency Research -- Jenn Chin's presentation
Cultural Competency Research -- Jenn Chin's presentation
 
Cells[1]
Cells[1]Cells[1]
Cells[1]
 
Marketing Agenzie di Viaggio
Marketing Agenzie di ViaggioMarketing Agenzie di Viaggio
Marketing Agenzie di Viaggio
 
Toolboxes wiifm2 optimised
Toolboxes wiifm2 optimisedToolboxes wiifm2 optimised
Toolboxes wiifm2 optimised
 
PLAY-fullness [Noun: Light-heartedness]
PLAY-fullness [Noun: Light-heartedness]PLAY-fullness [Noun: Light-heartedness]
PLAY-fullness [Noun: Light-heartedness]
 
Jano
Jano Jano
Jano
 
Realtor.org listing presentation
Realtor.org listing presentationRealtor.org listing presentation
Realtor.org listing presentation
 
Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...
 
Music insitutions
Music insitutionsMusic insitutions
Music insitutions
 
Startup Weekend Basel Outro
Startup Weekend Basel OutroStartup Weekend Basel Outro
Startup Weekend Basel Outro
 
Cells[1]
Cells[1]Cells[1]
Cells[1]
 
Photoshop designs presentation
Photoshop designs presentationPhotoshop designs presentation
Photoshop designs presentation
 
Leading Change in 21st Century Teacher Training
Leading Change in 21st Century Teacher TrainingLeading Change in 21st Century Teacher Training
Leading Change in 21st Century Teacher Training
 
Revista palabra de pichikeche IV
Revista palabra de pichikeche IVRevista palabra de pichikeche IV
Revista palabra de pichikeche IV
 

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

Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
Shinichi Ogawa
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
Shinichi Ogawa
 
When writing a member function of the HAMT class- the member function.pdf
When writing a member function of the HAMT class- the member function.pdfWhen writing a member function of the HAMT class- the member function.pdf
When writing a member function of the HAMT class- the member function.pdf
aadyaenterprisesnoid
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
Jano Suchal
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds Ls
ArrrrCamp
 
Backbone.js Simple Tutorial
Backbone.js Simple TutorialBackbone.js Simple Tutorial
Backbone.js Simple Tutorial
추근 문
 

Similar to レガシーコード改善ガイド (20)

Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
 
C++ Arrays different operations .pdf
C++ Arrays different operations .pdfC++ Arrays different operations .pdf
C++ Arrays different operations .pdf
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
 
When writing a member function of the HAMT class- the member function.pdf
When writing a member function of the HAMT class- the member function.pdfWhen writing a member function of the HAMT class- the member function.pdf
When writing a member function of the HAMT class- the member function.pdf
 
Jquery
JqueryJquery
Jquery
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Declarative Data Modeling in Python
Declarative Data Modeling in PythonDeclarative Data Modeling in Python
Declarative Data Modeling in Python
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds Ls
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And Tricks
 
Backbone.js Simple Tutorial
Backbone.js Simple TutorialBackbone.js Simple Tutorial
Backbone.js Simple Tutorial
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Java script
Java scriptJava script
Java script
 

More from Maki Toshio

Searched gems which supports only ruby 2.6
Searched gems which supports only ruby 2.6Searched gems which supports only ruby 2.6
Searched gems which supports only ruby 2.6
Maki Toshio
 
ファイルシステムのスナップショット機能でバックアップを取得する
ファイルシステムのスナップショット機能でバックアップを取得するファイルシステムのスナップショット機能でバックアップを取得する
ファイルシステムのスナップショット機能でバックアップを取得する
Maki Toshio
 
Rubyで簡単にremote access apiを実行する
Rubyで簡単にremote access apiを実行するRubyで簡単にremote access apiを実行する
Rubyで簡単にremote access apiを実行する
Maki Toshio
 

More from Maki Toshio (11)

Rails 6.1 → 7.0アップデート記録
Rails 6.1 → 7.0アップデート記録Rails 6.1 → 7.0アップデート記録
Rails 6.1 → 7.0アップデート記録
 
自社サービスのAPIをOAuth2対応にして公開した
自社サービスのAPIをOAuth2対応にして公開した自社サービスのAPIをOAuth2対応にして公開した
自社サービスのAPIをOAuth2対応にして公開した
 
Searched gems which supports only ruby 2.6
Searched gems which supports only ruby 2.6Searched gems which supports only ruby 2.6
Searched gems which supports only ruby 2.6
 
ActiveRecordで複雑なクエリを書くのは間違っているのか
ActiveRecordで複雑なクエリを書くのは間違っているのかActiveRecordで複雑なクエリを書くのは間違っているのか
ActiveRecordで複雑なクエリを書くのは間違っているのか
 
やさしいGemパッチの作り方
やさしいGemパッチの作り方やさしいGemパッチの作り方
やさしいGemパッチの作り方
 
ファイルシステムのスナップショット機能でバックアップを取得する
ファイルシステムのスナップショット機能でバックアップを取得するファイルシステムのスナップショット機能でバックアップを取得する
ファイルシステムのスナップショット機能でバックアップを取得する
 
Cloud Foundry Day in Tokyo Lightning Talk - Cloud Foundry over the Proxy
Cloud Foundry Day in Tokyo Lightning Talk - Cloud Foundry over the ProxyCloud Foundry Day in Tokyo Lightning Talk - Cloud Foundry over the Proxy
Cloud Foundry Day in Tokyo Lightning Talk - Cloud Foundry over the Proxy
 
メール製品を作って気づいたmailライブラリの光と闇について語る
メール製品を作って気づいたmailライブラリの光と闇について語るメール製品を作って気づいたmailライブラリの光と闇について語る
メール製品を作って気づいたmailライブラリの光と闇について語る
 
明日から使える(?)Rubyトリビア
明日から使える(?)Rubyトリビア明日から使える(?)Rubyトリビア
明日から使える(?)Rubyトリビア
 
Rubyで簡単にremote access apiを実行する
Rubyで簡単にremote access apiを実行するRubyで簡単にremote access apiを実行する
Rubyで簡単にremote access apiを実行する
 
Ruby on rails on hudsonの活用事例
Ruby on rails on hudsonの活用事例Ruby on rails on hudsonの活用事例
Ruby on rails on hudsonの活用事例
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

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

  • 1. 11 (Ruby Geek−− Cafe Toshio Maki(@Kirika_K2)
  • 2.
  • 3. sample class 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 } end end
  • 4. • •
  • 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
  • 8. def add_element(new_element) @elements << new_element end • @elements • element_count • element
  • 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. class Element attr_reader :name, :text def initialize(name) @name = name @text = "" end def add_text(new_text) @text += new_text end end • add_text elements
  • 12. require 'test/unit' require 'in_memory_directory' class 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")) end end
  • 13. $ ruby in_memory_directory_test.rb Loaded suite in_memory_directory_test Started .. Finished in 0.001858 seconds. 2 tests, 2 assertions, 0 failures, 0 errors
  • 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 } end end
  • 15. $ ruby in_memory_directory_test.rb Loaded suite in_memory_directory_test Started .F Finished 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. • add_element Index Element 2 •
  • 17. require 'test/unit' require 'in_memory_directory' class 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")) end end
  • 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 } end end
  • 19. ※ • static • final, const •

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n