SlideShare a Scribd company logo
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
Selfを考える

More Related Content

Similar to Selfを考える

Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
Jano 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 examples
Robert Lujo
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
Ígor Bonadio
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
François-Guillaume Ribreau
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 

Similar to Selfを考える (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 で書く 脆弱なコード
よしだ あつし
 
CTOのおしごと
CTOのおしごとCTOのおしごと
CTOのおしごと
よしだ あつし
 
Railsにコントリビュートしてきました
RailsにコントリビュートしてきましたRailsにコントリビュートしてきました
Railsにコントリビュートしてきました
よしだ あつし
 
Rubyコードの最適化
Rubyコードの最適化Rubyコードの最適化
Rubyコードの最適化
よしだ あつし
 
低レイヤから見たrubyプログラミング
低レイヤから見たrubyプログラミング低レイヤから見たrubyプログラミング
低レイヤから見たrubyプログラミング
よしだ あつし
 
まじょのおしごとの裏側
まじょのおしごとの裏側まじょのおしごとの裏側
まじょのおしごとの裏側
よしだ あつし
 
僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法僕が勉強をする モチベーションと勉強法
僕が勉強をする モチベーションと勉強法
よしだ あつし
 
Dockerプレゼン
DockerプレゼンDockerプレゼン
Dockerプレゼン
よしだ あつし
 
よい名前を付けましょう リーダブルなんたらとか
よい名前を付けましょう   リーダブルなんたらとかよい名前を付けましょう   リーダブルなんたらとか
よい名前を付けましょう リーダブルなんたらとか
よしだ あつし
 
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アプリをリリースよしだ あつし
 
テスト駆動開発入門
テスト駆動開発入門テスト駆動開発入門
テスト駆動開発入門
よしだ あつし
 
デバッガでデバッグしない
デバッガでデバッグしないデバッガでデバッグしない
デバッガでデバッグしない
よしだ あつし
 
Rails3使用雑感
Rails3使用雑感Rails3使用雑感
Rails3使用雑感
よしだ あつし
 
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

ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 

Recently uploaded (20)

ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 

Selfを考える