SlideShare a Scribd company logo
1 of 29
Download to read offline
self
@ 80 ruby
• :
• SNS: @yalab
• :
• : ( )
• ruby : since 1.6
• : ruby trunk mjit merge
1 name = "Yoshida" #
2 name.size #
1 name = "Yoshida" #
2 name.size #
1 name = "Yoshida" #
2 name.size #
1 public_methods
• )
• )
1 self.public_methods
"self"
Y^Y^Y^Y^Y^Y
self
1 p self #=> main
2
3 class A
4 p self #=> A
5 def method
6 p self #=> #<A:0x007fdf1002cf28>
7 end
8
9 def self.classmethod
10 p self #=> A
11 end
12 end
13
14 A.module_eval do
15 p self #=> A
16 end
1 class Animal
2 def type
3 :animal
4 end
5 end
6
7 class Human < Animal
8 def initialize(name)
9 @name = name
10 end
11
12 def name
13 "#{@name}(#{type})" #<- type
14 end
15 end
1 class User < ApplicationRecord
2 validates :name, presence: true
3 end
1 class User < ApplicationRecord
2 self.validates(:name, {presence: true})
3 end
1 class User < ApplicationRecord
2 validates :name, presence: true
3 end
)private
self
self
1 p self.class #=>
2 p self.class.ancestors #=>
3 p self.instance_variables #=>
4 p self.methods #=>
5 p self.methods.grep /write/ #=>
6 p self.method(:tap).source_location #=>
Object,Class,Module
https://docs.ruby-lang.org/ja/2.5.0/class/Object.html
https://docs.ruby-lang.org/ja/2.5.0/class/Class.html
https://docs.ruby-lang.org/ja/2.5.0/class/Module.html
self ruby
self
self
Understanding self in Ruby

More Related Content

Similar to Understanding self in Ruby

Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門S Akai
 
Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesRobert Lujo
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma IntroduçãoÍgor Bonadio
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 

Similar to Understanding self in Ruby (7)

Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examples
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 

More from よしだ あつし

serviceクラスをやめようサブクラスを使おう
serviceクラスをやめようサブクラスを使おうserviceクラスをやめようサブクラスを使おう
serviceクラスをやめようサブクラスを使おうよしだ あつし
 
ruby で書く 脆弱なコード
ruby で書く 脆弱なコードruby で書く 脆弱なコード
ruby で書く 脆弱なコードよしだ あつし
 
Railsにコントリビュートしてきました
RailsにコントリビュートしてきましたRailsにコントリビュートしてきました
Railsにコントリビュートしてきましたよしだ あつし
 
低レイヤから見たrubyプログラミング
低レイヤから見たrubyプログラミング低レイヤから見たrubyプログラミング
低レイヤから見たrubyプログラミングよしだ あつし
 
まじょのおしごとの裏側
まじょのおしごとの裏側まじょのおしごとの裏側
まじょのおしごとの裏側よしだ あつし
 
僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法よしだ あつし
 
よい名前を付けましょう リーダブルなんたらとか
よい名前を付けましょう   リーダブルなんたらとかよい名前を付けましょう   リーダブルなんたらとか
よい名前を付けましょう リーダブルなんたらとかよしだ あつし
 
私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development について私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development についてよしだ あつし
 
15分でできるSQLインジェクション
15分でできるSQLインジェクション15分でできるSQLインジェクション
15分でできるSQLインジェクションよしだ あつし
 
Next GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリースNext GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリースよしだ あつし
 
デバッガでデバッグしない
デバッガでデバッグしないデバッガでデバッグしない
デバッガでデバッグしないよしだ あつし
 
Twitterでネットストーカーをしよう
TwitterでネットストーカーをしようTwitterでネットストーカーをしよう
Twitterでネットストーカーをしようよしだ あつし
 

More from よしだ あつし (20)

serviceクラスをやめようサブクラスを使おう
serviceクラスをやめようサブクラスを使おうserviceクラスをやめようサブクラスを使おう
serviceクラスをやめようサブクラスを使おう
 
ruby で書く 脆弱なコード
ruby で書く 脆弱なコードruby で書く 脆弱なコード
ruby で書く 脆弱なコード
 
CTOのおしごと
CTOのおしごとCTOのおしごと
CTOのおしごと
 
Railsにコントリビュートしてきました
RailsにコントリビュートしてきましたRailsにコントリビュートしてきました
Railsにコントリビュートしてきました
 
Rubyコードの最適化
Rubyコードの最適化Rubyコードの最適化
Rubyコードの最適化
 
低レイヤから見たrubyプログラミング
低レイヤから見たrubyプログラミング低レイヤから見たrubyプログラミング
低レイヤから見たrubyプログラミング
 
まじょのおしごとの裏側
まじょのおしごとの裏側まじょのおしごとの裏側
まじょのおしごとの裏側
 
僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法
 
Dockerプレゼン
DockerプレゼンDockerプレゼン
Dockerプレゼン
 
Vue.js ハンズオン資料
Vue.js ハンズオン資料Vue.js ハンズオン資料
Vue.js ハンズオン資料
 
よい名前を付けましょう リーダブルなんたらとか
よい名前を付けましょう   リーダブルなんたらとかよい名前を付けましょう   リーダブルなんたらとか
よい名前を付けましょう リーダブルなんたらとか
 
Gitの使い方あれこれ
Gitの使い方あれこれGitの使い方あれこれ
Gitの使い方あれこれ
 
私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development について私はいかにしてpull request を行ったか - あるいは social development について
私はいかにしてpull request を行ったか - あるいは social development について
 
15分でできるSQLインジェクション
15分でできるSQLインジェクション15分でできるSQLインジェクション
15分でできるSQLインジェクション
 
Next GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリースNext GAE Heroku を使って 3分でRailsアプリをリリース
Next GAE Heroku を使って 3分でRailsアプリをリリース
 
テスト駆動開発入門
テスト駆動開発入門テスト駆動開発入門
テスト駆動開発入門
 
Railsの今昔
Railsの今昔Railsの今昔
Railsの今昔
 
デバッガでデバッグしない
デバッガでデバッグしないデバッガでデバッグしない
デバッガでデバッグしない
 
Rails3使用雑感
Rails3使用雑感Rails3使用雑感
Rails3使用雑感
 
Twitterでネットストーカーをしよう
TwitterでネットストーカーをしようTwitterでネットストーカーをしよう
Twitterでネットストーカーをしよう
 

Recently uploaded

welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 

Recently uploaded (20)

welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 

Understanding self in Ruby