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

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
 

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 #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
 
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.pdfaadyaenterprisesnoid
 
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추근 문
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 

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

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
 

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

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
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 ImpactPECB
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
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.pptxheathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
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
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

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

  • 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