Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rummaging around the stdlib
Search
jswanner
April 09, 2015
Programming
0
55
Rummaging around the stdlib
Presented at an ORUG meeting
jswanner
April 09, 2015
Tweet
Share
More Decks by jswanner
See All by jswanner
ActiveRecord Scopes & Arel [RailsWayCon Version]
jswanner
3
160
ActiveRecord Scopes & Arel
jswanner
6
1.2k
Other Decks in Programming
See All in Programming
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
50
32k
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
240
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
170
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
320
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
660
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
680
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
170
Team operations that are not burdened by SRE
kazatohiei
1
290
#QiitaBash MCPのセキュリティ
ryosukedtomita
0
670
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
150
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
0
470
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
330
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
7
500
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Being A Developer After 40
akosma
90
590k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
940
Designing for humans not robots
tammielis
253
25k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
680
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Writing Fast Ruby
sferik
628
62k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Transcript
Rummaging around the stdlib Jacob Swanner @jswanner
Definition of stdlib
Not a library of these
Definition of stdlib • Ships with the language • Separate
from “core” • Opt-in parts of the language
Old Identification Scheme • Something you needed to `require` •
Doesn’t quite work anymore
New Identification Scheme • Use documentation • Core: http://ruby-doc.org/core-2.2.1/ •
stdlib: http://ruby-doc.org/stdlib-2.2.1/
Common Parts • base64 • csv • erb • fileutils
• json • logger • net/http • pathname • pp • securerandom • webrick • yaml
Confusing Parts: Time $ irb >> Time.new(2015, 4, 9) =>
2015-04-09 00:00:00 -0400 >> Time.parse('2015-04-09') NoMethodError: undefined method `parse' for Time:Class >> require 'time' => true >> Time.parse('2015-04-09') => 2015-04-09 00:00:00 -0400
Confusing Parts: Date $ irb >> Date.new(2015, 4, 9) NameError:
uninitialized constant Date >> require 'date' => true >> Date.new(2015, 4, 9) => #<Date: 2015-04-09 ((2457122j,0s,0n),+0s,2299161j)> >> Date.parse('2015-04-09') => #<Date: 2015-04-09 ((2457122j,0s,0n),+0s,2299161j)>
Confusing Parts: RubyGems $ irb >> Gem => Gem >>
require 'rails' => true $ ruby --disable-gems -S -- irb >> Gem NameError: uninitialized constant Gem >> require 'rails' LoadError: cannot load such file -- rails
Lesser Known: ipaddr $ irb -r ipaddr >> IPAddr.new('10.0.0.256') IPAddr::InvalidAddressError:
invalid address >> ip = IPAddr.new('10.0.0.10') => #<IPAddr: IPv4:10.0.0.10/255.255.255.255> >> ip.succ => #<IPAddr: IPv4:10.0.0.11/255.255.255.255> >> ip.ipv6? => false >> ip_range = ip.mask(24) => #<IPAddr: IPv4:10.0.0.0/255.255.255.0> >> ip_range.include?(ip) => true
Lesser Known: irb #!/usr/bin/env ruby require 'irb' # require application
code # perform application boot IRB.start(__FILE__)
Buried Treasure: FileList $ irb -r rake/file_list >> existing =
Rake::FileList.new("*.markdown") => ["a.markdown", "b.markdown", "c.markdown"] >> renamed = existing.ext(".md") => ["a.md", "b.md", "c.md"] >> existing.zip(renamed). ?> each { |from, to| FileUtils.mv(from, to) } => [["a.markdown", "a.md"], ["b.markdown", "b.md"], ["c.markdown", "c.md"]]
FileList, cont’d $ tree ├── lib/ │ ├── a.rb │
├── b.rb │ └── c.rb └── test/ ├── a_test.rb └── c_test.rb
FileList, cont’d $ irb -r rake/file_list >> source = Rake::FileList.new("lib/*.rb")
=> ["lib/a.rb", "lib/b.rb", "lib/c.rb"] >> tests = Rake::FileList.new("test/*_test.rb") => ["test/a_test.rb", "test/c_test.rb"] >> untested = source. ?> sub(‘lib/‘, 'test/').sub('.rb', '_test.rb'). ?> exclude { |f| tests.include?(f) } => ["test/b_test.rb"]
YAML::Store $ irb -r yaml/store >> store = YAML::Store.new("store.yml") =>
#<Psych::Store:0x007f9b8f5b2430 …> >> store.transaction do ?> store["people"] = ["dray", "jacob", "nate"] ?> store["time"] = Time.now ?> end => … >> store["people"] PStore::Error: not in transaction
YAML::Store, cont’d $ cat store.yml --- people: - dray -
jacob - nate time: 2015-04-09 16:23:58.394957000 -04:00
Quirky: un $ irb -I lib -r date $ irb
-Ilib -rdate
Quirky: un, cont’d ruby -run -e cp -- [OPTION] SOURCE
DEST ruby -run -e ln -- [OPTION] TARGET LINK_NAME ruby -run -e mv -- [OPTION] SOURCE DEST ruby -run -e rm -- [OPTION] FILE ruby -run -e mkdir -- [OPTION] DIR ruby -run -e rmdir -- [OPTION] DIR ruby -run -e install -- [OPTION] SOURCE DEST ruby -run -e touch -- [OPTION] FILE ruby -run -e wait_writable -- [OPTION] FILE ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION] ruby -run -e httpd -- [OPTION] DocumentRoot ruby -run -e help [COMMAND]
Quirky: un, cont’d $ ruby -run -e httpd -- --port
8888 . & […] INFO WEBrick::HTTPServer#start: port=8888 $ curl "http://localhost:8888/store.yml" --- people: - dray - jacob - nate time: 2015-04-09 16:23:58.394957000 -04:00
Quirky: ubygems $ cat $RUBY_ROOT/lib/ruby/2.2.0/ubygems.rb # This file allows for
the running of rubygems with a nice # command line look-and-feel: ruby -rubygems foo.rb #-- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. # All rights reserved. # See LICENSE.txt for permissions. #++ require 'rubygems'
• CDC/ C. Goldsmith, P. Feorino, E. L. Palmer, W.
R. McManus http:// en.wikipedia.org/wiki/HIV/AIDS#/media/File:HIV-budding-Color.jpg • http://commons.wikimedia.org/wiki/User:Nephron http://en.wikipedia.org/wiki/ Herpes_simplex_virus#/media/File:Herpes_simplex_virus_pap_test.jpg • http://en.wikipedia.org/wiki/Chlamydia_infection#/media/ File:Pap_smear_showing_clamydia_in_the_vacuoles_500x_H%26E.jpg