SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
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



•
•

•

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

Tokyo at Child Scale
Tokyo at Child ScaleTokyo at Child Scale
Tokyo at Child Scalea-small-lab
 
Un dia a l'escola 1
Un dia a l'escola 1Un dia a l'escola 1
Un dia a l'escola 1nurisaba
 
Race Horse Steroids
Race Horse SteroidsRace Horse Steroids
Race Horse Steroidsnorrell44294
 
Southwest Ideas Investor Conference Presentation
Southwest Ideas Investor Conference PresentationSouthwest Ideas Investor Conference Presentation
Southwest Ideas Investor Conference Presentationharleyebarnes
 
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 presentationinterculturalpg
 
Marketing Agenzie di Viaggio
Marketing Agenzie di ViaggioMarketing Agenzie di Viaggio
Marketing Agenzie di ViaggioT SOLUTIONS
 
PLAY-fullness [Noun: Light-heartedness]
PLAY-fullness [Noun: Light-heartedness]PLAY-fullness [Noun: Light-heartedness]
PLAY-fullness [Noun: Light-heartedness]a-small-lab
 
Realtor.org listing presentation
Realtor.org listing presentationRealtor.org listing presentation
Realtor.org listing presentationMichael Yurovsky
 
Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...Hackathons - learnings, tips and tricks...
Hackathons - learnings, tips and tricks...Lasse Chor
 
Startup Weekend Basel Outro
Startup Weekend Basel OutroStartup Weekend Basel Outro
Startup Weekend Basel OutroLasse Chor
 
Photoshop designs presentation
Photoshop designs presentationPhotoshop designs presentation
Photoshop designs presentationJames Green
 
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 TrainingSally Sanchez
 
Revista palabra de pichikeche IV
Revista palabra de pichikeche IVRevista palabra de pichikeche IV
Revista palabra de pichikeche IVkomunidad
 

Destaque (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
 

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

Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2aShinichi Ogawa
 
C++ Arrays different operations .pdf
C++ Arrays different operations .pdfC++ Arrays different operations .pdf
C++ Arrays different operations .pdfmanahilzulfiqar6
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
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 modelsKostyantyn Stepanyuk
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1Shinichi Ogawa
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1Jano Suchal
 
Declarative Data Modeling in Python
Declarative Data Modeling in PythonDeclarative Data Modeling in Python
Declarative Data Modeling in PythonJoshua Forman
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds LsArrrrCamp
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)BoneyGawande
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
jQuery - Tips And Tricks
jQuery - Tips And TricksjQuery - Tips And Tricks
jQuery - Tips And TricksLester Lievens
 
Backbone.js Simple Tutorial
Backbone.js Simple TutorialBackbone.js Simple Tutorial
Backbone.js Simple Tutorial추근 문
 
Python progemmingdesign andimplement a programwith certain com.pdf
Python progemmingdesign andimplement a programwith certain com.pdfPython progemmingdesign andimplement a programwith certain com.pdf
Python progemmingdesign andimplement a programwith certain com.pdfjyothimuppasani1
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 

Semelhante a レガシーコード改善ガイド (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
 
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
 
Python progemmingdesign andimplement a programwith certain com.pdf
Python progemmingdesign andimplement a programwith certain com.pdfPython progemmingdesign andimplement a programwith certain com.pdf
Python progemmingdesign andimplement a programwith certain com.pdf
 
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
 

Mais de Maki Toshio

Rails 6.1 → 7.0アップデート記録
Rails 6.1 → 7.0アップデート記録Rails 6.1 → 7.0アップデート記録
Rails 6.1 → 7.0アップデート記録Maki Toshio
 
自社サービスのAPIをOAuth2対応にして公開した
自社サービスのAPIをOAuth2対応にして公開した自社サービスのAPIをOAuth2対応にして公開した
自社サービスのAPIをOAuth2対応にして公開した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.6Maki Toshio
 
ActiveRecordで複雑なクエリを書くのは間違っているのか
ActiveRecordで複雑なクエリを書くのは間違っているのかActiveRecordで複雑なクエリを書くのは間違っているのか
ActiveRecordで複雑なクエリを書くのは間違っているのかMaki Toshio
 
やさしいGemパッチの作り方
やさしいGemパッチの作り方やさしいGemパッチの作り方
やさしいGemパッチの作り方Maki Toshio
 
ファイルシステムのスナップショット機能でバックアップを取得する
ファイルシステムのスナップショット機能でバックアップを取得するファイルシステムのスナップショット機能でバックアップを取得する
ファイルシステムのスナップショット機能でバックアップを取得するMaki Toshio
 
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 ProxyMaki Toshio
 
メール製品を作って気づいたmailライブラリの光と闇について語る
メール製品を作って気づいたmailライブラリの光と闇について語るメール製品を作って気づいたmailライブラリの光と闇について語る
メール製品を作って気づいたmailライブラリの光と闇について語るMaki Toshio
 
明日から使える(?)Rubyトリビア
明日から使える(?)Rubyトリビア明日から使える(?)Rubyトリビア
明日から使える(?)RubyトリビアMaki Toshio
 
Rubyで簡単にremote access apiを実行する
Rubyで簡単にremote access apiを実行するRubyで簡単にremote access apiを実行する
Rubyで簡単にremote access apiを実行するMaki Toshio
 
Ruby on rails on hudsonの活用事例
Ruby on rails on hudsonの活用事例Ruby on rails on hudsonの活用事例
Ruby on rails on hudsonの活用事例Maki Toshio
 

Mais de 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の活用事例
 

Último

The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxheathfieldcps1
 
LEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudLEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudDr. Bruce A. Johnson
 
POST ENCEPHALITIS case study Jitendra bhargav
POST ENCEPHALITIS case study  Jitendra bhargavPOST ENCEPHALITIS case study  Jitendra bhargav
POST ENCEPHALITIS case study Jitendra bhargavJitendra Bhargav
 
LEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollLEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollDr. Bruce A. Johnson
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsDhatriParmar
 
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxBBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxProf. Kanchan Kumari
 
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptxMetabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptxDr. Santhosh Kumar. N
 
Riti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptxRiti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptxDhatriParmar
 
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSDLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSTeacherNicaPrintable
 
VIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfVIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfArthyR3
 
UNIT I Design Thinking and Explore.pptx
UNIT I  Design Thinking and Explore.pptxUNIT I  Design Thinking and Explore.pptx
UNIT I Design Thinking and Explore.pptxGOWSIKRAJA PALANISAMY
 
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...Nguyen Thanh Tu Collection
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxiammrhaywood
 
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in PharmacyASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in PharmacySumit Tiwari
 
Dhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhatriParmar
 
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...Subham Panja
 
Pharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfPharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfSumit Tiwari
 
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdfArti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdfwill854175
 
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...AKSHAYMAGAR17
 
The First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfThe First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfdogden2
 

Último (20)

The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 
LEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudLEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced Stud
 
POST ENCEPHALITIS case study Jitendra bhargav
POST ENCEPHALITIS case study  Jitendra bhargavPOST ENCEPHALITIS case study  Jitendra bhargav
POST ENCEPHALITIS case study Jitendra bhargav
 
LEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollLEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community Coll
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian Poetics
 
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxBBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
 
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptxMetabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
 
Riti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptxRiti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptx
 
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSDLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
 
VIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfVIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdf
 
UNIT I Design Thinking and Explore.pptx
UNIT I  Design Thinking and Explore.pptxUNIT I  Design Thinking and Explore.pptx
UNIT I Design Thinking and Explore.pptx
 
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
 
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in PharmacyASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
 
Dhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian Poetics
 
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
 
Pharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfPharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdf
 
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdfArti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
 
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
 
The First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfThe First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.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 •

Notas do Editor

  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