Submit Search
Upload
あまり知られていないRubyの便利機能
•
0 likes
•
204 views
K
Kazuhiro Nishiyama
Follow
[鹿児島Ruby会議01](https://k-ruby.github.io/kagoshima-rubykaigi01/)での発表資料です。
Read less
Read more
Technology
Report
Share
Report
Share
1 of 15
Download now
Download to read offline
Recommended
Sensor architecturestartingpoint
Sensor architecturestartingpoint
Prashun Javeri
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
Robin Xiao
Difference between php and node
Difference between php and node
Nguyễn Ngọc Phương
appborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-system
endian7000
The Rust Programming Language
The Rust Programming Language
Mario Alexandro Santini
Coding in the context era
Coding in the context era
lestrrat
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Gosuke Miyashita
Building a REST API with Node.js and MongoDB
Building a REST API with Node.js and MongoDB
VivochaLabs
Recommended
Sensor architecturestartingpoint
Sensor architecturestartingpoint
Prashun Javeri
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
Robin Xiao
Difference between php and node
Difference between php and node
Nguyễn Ngọc Phương
appborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-system
endian7000
The Rust Programming Language
The Rust Programming Language
Mario Alexandro Santini
Coding in the context era
Coding in the context era
lestrrat
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Xen Summit 2008 Tokyo - Operating Xen domains through LL(Perl/Python) with li...
Gosuke Miyashita
Building a REST API with Node.js and MongoDB
Building a REST API with Node.js and MongoDB
VivochaLabs
MongoDB, Node.js And You: PART II
MongoDB, Node.js And You: PART II
Mitch Pirtle
Node.js for Rubists
Node.js for Rubists
Sagiv Ofek
Groovy a Scripting Language for Java
Groovy a Scripting Language for Java
Charles Anderson
20140918 ruby kaigi2014
20140918 ruby kaigi2014
Hiroshi SHIBATA
Ruby's GC 20
Ruby's GC 20
Narihiro Nakamura
Introduction to Python
Introduction to Python
Sway Wang
The art of concurrent programming
The art of concurrent programming
Iskren Chernev
Ubuntuのriscv64版をqemuで動かした at LILO&東海道らぐオフラインミーティング 2024-04-27
Ubuntuのriscv64版をqemuで動かした at LILO&東海道らぐオフラインミーティング 2024-04-27
Kazuhiro Nishiyama
lilo.linux.or.jp を buster から bullseye に上げた
lilo.linux.or.jp を buster から bullseye に上げた
Kazuhiro Nishiyama
小規模個人アプリをRails 7.xにバージョンアップした話
小規模個人アプリをRails 7.xにバージョンアップした話
Kazuhiro Nishiyama
Ruby リファレンスマニュアル改善計画 2022 進捗報告
Ruby リファレンスマニュアル改善計画 2022 進捗報告
Kazuhiro Nishiyama
fukuoka03-rubima-reboot-rubyist-magazine-reboot.pdf
fukuoka03-rubima-reboot-rubyist-magazine-reboot.pdf
Kazuhiro Nishiyama
rubykaigi2022-rurema-history-and-future.pdf
rubykaigi2022-rurema-history-and-future.pdf
Kazuhiro Nishiyama
qemuのriscv64にDebianを入れてみた
qemuのriscv64にDebianを入れてみた
Kazuhiro Nishiyama
systemd 再入門
systemd 再入門
Kazuhiro Nishiyama
Ruby 3.0.0 コネタ集
Ruby 3.0.0 コネタ集
Kazuhiro Nishiyama
livedoor天気API終了対応
livedoor天気API終了対応
Kazuhiro Nishiyama
Wireguard 実践入門
Wireguard 実践入門
Kazuhiro Nishiyama
workflow,job,step の使い分けの基準を考える
workflow,job,step の使い分けの基準を考える
Kazuhiro Nishiyama
Dockerのオフィシャルrubyイメージとは?
Dockerのオフィシャルrubyイメージとは?
Kazuhiro Nishiyama
チャットボットのススメ
チャットボットのススメ
Kazuhiro Nishiyama
Dokku の紹介
Dokku の紹介
Kazuhiro Nishiyama
More Related Content
What's hot
MongoDB, Node.js And You: PART II
MongoDB, Node.js And You: PART II
Mitch Pirtle
Node.js for Rubists
Node.js for Rubists
Sagiv Ofek
Groovy a Scripting Language for Java
Groovy a Scripting Language for Java
Charles Anderson
20140918 ruby kaigi2014
20140918 ruby kaigi2014
Hiroshi SHIBATA
Ruby's GC 20
Ruby's GC 20
Narihiro Nakamura
Introduction to Python
Introduction to Python
Sway Wang
The art of concurrent programming
The art of concurrent programming
Iskren Chernev
What's hot
(7)
MongoDB, Node.js And You: PART II
MongoDB, Node.js And You: PART II
Node.js for Rubists
Node.js for Rubists
Groovy a Scripting Language for Java
Groovy a Scripting Language for Java
20140918 ruby kaigi2014
20140918 ruby kaigi2014
Ruby's GC 20
Ruby's GC 20
Introduction to Python
Introduction to Python
The art of concurrent programming
The art of concurrent programming
More from Kazuhiro Nishiyama
Ubuntuのriscv64版をqemuで動かした at LILO&東海道らぐオフラインミーティング 2024-04-27
Ubuntuのriscv64版をqemuで動かした at LILO&東海道らぐオフラインミーティング 2024-04-27
Kazuhiro Nishiyama
lilo.linux.or.jp を buster から bullseye に上げた
lilo.linux.or.jp を buster から bullseye に上げた
Kazuhiro Nishiyama
小規模個人アプリをRails 7.xにバージョンアップした話
小規模個人アプリをRails 7.xにバージョンアップした話
Kazuhiro Nishiyama
Ruby リファレンスマニュアル改善計画 2022 進捗報告
Ruby リファレンスマニュアル改善計画 2022 進捗報告
Kazuhiro Nishiyama
fukuoka03-rubima-reboot-rubyist-magazine-reboot.pdf
fukuoka03-rubima-reboot-rubyist-magazine-reboot.pdf
Kazuhiro Nishiyama
rubykaigi2022-rurema-history-and-future.pdf
rubykaigi2022-rurema-history-and-future.pdf
Kazuhiro Nishiyama
qemuのriscv64にDebianを入れてみた
qemuのriscv64にDebianを入れてみた
Kazuhiro Nishiyama
systemd 再入門
systemd 再入門
Kazuhiro Nishiyama
Ruby 3.0.0 コネタ集
Ruby 3.0.0 コネタ集
Kazuhiro Nishiyama
livedoor天気API終了対応
livedoor天気API終了対応
Kazuhiro Nishiyama
Wireguard 実践入門
Wireguard 実践入門
Kazuhiro Nishiyama
workflow,job,step の使い分けの基準を考える
workflow,job,step の使い分けの基準を考える
Kazuhiro Nishiyama
Dockerのオフィシャルrubyイメージとは?
Dockerのオフィシャルrubyイメージとは?
Kazuhiro Nishiyama
チャットボットのススメ
チャットボットのススメ
Kazuhiro Nishiyama
Dokku の紹介
Dokku の紹介
Kazuhiro Nishiyama
Action Cableで簡易チャットを作ってみた
Action Cableで簡易チャットを作ってみた
Kazuhiro Nishiyama
Ruby svn to git
Ruby svn to git
Kazuhiro Nishiyama
Ruby 2.6 Update
Ruby 2.6 Update
Kazuhiro Nishiyama
最近のrubyのインストール方法
最近のrubyのインストール方法
Kazuhiro Nishiyama
Language update 2018 - ruby
Language update 2018 - ruby
Kazuhiro Nishiyama
More from Kazuhiro Nishiyama
(20)
Ubuntuのriscv64版をqemuで動かした at LILO&東海道らぐオフラインミーティング 2024-04-27
Ubuntuのriscv64版をqemuで動かした at LILO&東海道らぐオフラインミーティング 2024-04-27
lilo.linux.or.jp を buster から bullseye に上げた
lilo.linux.or.jp を buster から bullseye に上げた
小規模個人アプリをRails 7.xにバージョンアップした話
小規模個人アプリをRails 7.xにバージョンアップした話
Ruby リファレンスマニュアル改善計画 2022 進捗報告
Ruby リファレンスマニュアル改善計画 2022 進捗報告
fukuoka03-rubima-reboot-rubyist-magazine-reboot.pdf
fukuoka03-rubima-reboot-rubyist-magazine-reboot.pdf
rubykaigi2022-rurema-history-and-future.pdf
rubykaigi2022-rurema-history-and-future.pdf
qemuのriscv64にDebianを入れてみた
qemuのriscv64にDebianを入れてみた
systemd 再入門
systemd 再入門
Ruby 3.0.0 コネタ集
Ruby 3.0.0 コネタ集
livedoor天気API終了対応
livedoor天気API終了対応
Wireguard 実践入門
Wireguard 実践入門
workflow,job,step の使い分けの基準を考える
workflow,job,step の使い分けの基準を考える
Dockerのオフィシャルrubyイメージとは?
Dockerのオフィシャルrubyイメージとは?
チャットボットのススメ
チャットボットのススメ
Dokku の紹介
Dokku の紹介
Action Cableで簡易チャットを作ってみた
Action Cableで簡易チャットを作ってみた
Ruby svn to git
Ruby svn to git
Ruby 2.6 Update
Ruby 2.6 Update
最近のrubyのインストール方法
最近のrubyのインストール方法
Language update 2018 - ruby
Language update 2018 - ruby
Recently uploaded
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
sudhanshuwaghmare1
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
johnbeverley2021
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Angeliki Cooney
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
UiPathCommunity
Architecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
apidays
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
danishmna97
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
DianaGray10
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Zilliz
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Rustici Software
Elevate Developer Efficiency & build GenAI Application with Amazon Q
Elevate Developer Efficiency & build GenAI Application with Amazon Q
Bhuvaneswari Subramani
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Andrey Devyatkin
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
Remote DBA Services
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
sammart93
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Edi Saputra
Recently uploaded
(20)
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Architecting Cloud Native Applications
Architecting Cloud Native Applications
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Elevate Developer Efficiency & build GenAI Application with Amazon Q
Elevate Developer Efficiency & build GenAI Application with Amazon Q
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
あまり知られていないRubyの便利機能
1.
あまり知られていないRuby の便利機能 Kazuhiro NISHIYAMA 鹿児島Ruby会議01 2019/11/30 株式会社Ruby開発 Powered by
Rabbit 2.2.1
2.
自己紹介 西山 和広 Ruby のコミッター twitter,
github など: @znz 株式会社Ruby開発 www.ruby-dev.jp 1/14
3.
String#undump String#dump ⇄ String#undump since
ruby 2.5 String#dump ≠ String#inspect String#undump ≠ eval 2/14
4.
Hash#transform_* convert from Hash
to Hash Hash#transform_values{|v|...} since ruby 2.4 Hash#transform_keys{|k|...} since ruby 2.5 3/14
5.
Hash#to_h with block Hash#to_h{|k,v|...} with
block since ruby 2.6 without block since ruby 2.0.0 4/14
6.
warn with uplevel: old:
warn "#{caller(1, 1)[0]}: warning: message" new: warn "message", uplevel: 1 since ruby 2.5 5/14
7.
abort(message) abort("failed message") ≒ warn("failed
message"); exit(false) 6/14
8.
rand(range) rand(range) rand(1..6) since ruby 1.9.3 NG:
rand(endless_range) rand(1..) Errno::EDOM (Numerical argument out of domain) 7/14
9.
String.new String.new.encoding → ASCII-8BIT String.new(encoding:
'euc- jp').encoding → EUC-JP ''.dup → UTF-8 (script encoding) +'' → UTF-8 (script encoding) ''.+@ (for method chain) (useful with frozen string literal) 8/14
10.
String#gsub(pattern, hash) string.gsub(/['&"<>]/, { "'" =>
''', '&' => '&', '"' => '"', '<' => '<', '>' => '>', }) 9/14
11.
Regexp.union Regexp.union #=> /(?!)/ Regexp.union("penzance")
#=> /penzance/ Regexp.union("a+b*c") #=> /a+b*c/ Regexp.union("skiing", "sledding") Regexp.union(["skiing", "sledding"]) #=> /skiing|sledding/ Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/ 10/14
12.
String#*_with? "hello".start_with?("hell") #=> true "hello".start_with?(/H/i)
#=> true # returns true if one of the prefixes matches. "hello".start_with?("heaven", "hell") #=> true "hello".start_with?("heaven", "paradise") #=> false "hello".end_with?("ello") #=> true # returns true if one of the +suffixes+ matches. "hello".end_with?("heaven", "ello") #=> true "hello".end_with?("heaven", "paradise") #=> false NG: starts_with?, ends_with? 11/14
13.
String#{prepend,delet e_prefix,delete_suffix,c homp,chop} "end".prepend("prep") #=> "prepend" "prefix".delete_prefix("pre")
#=> "fix" "suffix".delete_suffix("fix") #=> "suf" "suffix".chomp("fix") #=> "fix" "hellorn".chomp #=> "hello" "hellorn".chop #=> "hello" 12/14
14.
String#{delete,tr} "hello".delete "l","lo" #=>
"heo" "hello".delete "lo" #=> "he" "hello".delete "aeiou", "^e" #=> "hell" "hello".delete "ej-m" #=> "ho" "hello".tr('el', 'ip') #=> "hippo" "hello".tr('a-y', 'b-z') #=> "ifmmp" "hello".tr('^aeiou', '*') #=> "*e**o" 13/14
15.
参考文献 リファレンスマニュアル https://docs.ruby-lang.org/ja/ 間違いなどを見つけたら https://github.com/rurema/doctree もっと気軽に確認したいなら https://ruby-jp.github.io/ ruby-jp Slack の
#rurema など 14/14Powered by Rabbit 2.2.1
Download now