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
RubyJS at rubyconf.tw
Search
hasclass
December 07, 2012
Programming
2
680
RubyJS at rubyconf.tw
lightning talk
hasclass
December 07, 2012
Tweet
Share
More Decks by hasclass
See All by hasclass
RubyJS
hasclass
1
230
Other Decks in Programming
See All in Programming
State of Namespace
tagomoris
3
530
Building Scalable Mobile Projects: Fast Builds, High Reusability and Clear Ownership
cyrilmottier
2
250
Empowering Developers with HTML-Aware ERB Tooling @ RubyKaigi 2025, Matsuyama, Ehime
marcoroth
1
210
リアルタイムレイトレーシング + ニューラルレンダリング簡単紹介 / Real-Time Ray Tracing & Neural Rendering: A Quick Introduction (2025)
shocker_0x15
1
290
Kubernetesで実現できるPlatform Engineering の現在地
nwiizo
3
1.9k
Unlock the Potential of Swift Code Generation
rockname
0
240
「”誤った使い方をすることが困難”な設計」で良いコードの基礎を固めよう / phpcon-odawara-2025
taniguhey
0
100
Vibe Codingをせずに Clineを使っている
watany
17
5.9k
CRE Meetup!ユーザー信頼性を支えるエンジニアリング実践例の発表資料です
tmnb
0
620
Qiita Bash
mercury_dev0517
1
180
gen_statem - OTP's Unsung Hero
whatyouhide
1
190
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
6
820
Featured
See All Featured
Designing for Performance
lara
607
69k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Typedesign – Prime Four
hannesfritz
41
2.6k
How to train your dragon (web standard)
notwaldorf
91
6k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
How GitHub (no longer) Works
holman
314
140k
Docker and Python
trallard
44
3.3k
A designer walks into a library…
pauljervisheath
205
24k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
520
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.2k
Agile that works and the tools we love
rasmusluckow
328
21k
Transcript
RubyJS alpha www.rubyjs.org twi5er.com/hasclass
50 slides in 5 minutes
None
None
A port of Ruby core-‐lib to JS • String,
Regexp, MatchData • Array, Enumerable, Enumerator • Numeric (Integer/Fixnum, Float) • Range • Time, Hash coming soon
JS Methods Array jjjjjjjjjjjjj Enumerable Fixnum Float jjjj Integer
Kernel Matchdata Numeric Range Regexp jj String jjjjjjjjjjjjj
RubyJS Methods Array jjjjjjjjjjjjj................................. ............................ Enumerable .............................................. Fixnum ...........................
Float jjjj.............................. Integer .................... Kernel ... Matchdata ..................... Numeric ....................... Range ...................... Regexp jj...................... String jjjjjjjjjjjjj................................ ...........................
Compliant to Ruby No surprises.. Rubinius Rubyspecs ported
to JS
str = "a"
str = R("a”) #=> R.String
str = R("a") str.capitalize() #=> R.String #=> A
str = R("a") str.capitalize() .upto('C') #=> R.Enumerator
str = R("a") str.capitalize() .upto('C’) .each_cons(2, function (a,b) {
R.puts("#{a} to the #{b}") }) # A to the B # B to the C
str = R("a") str.capitalize() .upto('C’) .to_a() #=> R.Array #=>
[A, B, C]
str = R("a") str.capitalize() .upto('C’) .to_a() .join(', ') #=>
R.String #=> ’A, B, C'
str = R("a") str.capitalize() .upto('C’) .to_a() .join(', ') .ljust(10,
‘-’) #=> R.String #=> ’A, B, C---'
str = R("a") str.capitalize() .upto('C’) .to_a() .join(', ') .ljust(10,
‘-’) .to_native(); #=> string #=> ’A, B, C---'
RubyJS objects are wrappers Around naMve JS objects
Wrapper class RubyJS.Fixnum @include RubyJS.Comparable constructor: (__native__) ->
@__native__ = __native__; #=> new R.Fixnum(2)
Wrapper class RubyJS.Fixnum @include RubyJS.Comparable constructor: (@__native__) ->
odd: -> @__native__ % 2 != 0
Wrapper class RubyJS.Fixnum @include RubyJS.Comparable constructor: (@__native__) ->
odd: -> @__native__ % 2 != 0 next: -> new R.Fixnum(@__native__ + 1)
PorMng Ruby Code to JS
Ruby arr = %w(looks feels acts) arr.map {|w|
w.capitalize } .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
RubyJS arr = R.w('looks feels acts')
RubyJS arr = R.w('looks feels acts') arr.map
{|w| w.capitalize }
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() )
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
Ruby arr = %w(looks feels acts) arr.map
{|w| w.capitalize } .join(", ") .concat(" like Ruby") .center(35, '-’) '---Looks, Feels, Acts like Ruby---’
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
Symbol#to_proc arr = R.w('looks feels acts') arr.map(
R.proc('capitalize’) ) .join(", ") .concat(" like Ruby") .center(35, '-')
Symbol#to_proc arr = R.w('looks feels acts') arr.map(
R.proc(’ljust’, 35) ) .join(", ") .concat(" like Ruby") .center(35, '-')
But I can do with library x, y ,z
arr = ['looks', 'feels', 'acts']; str = _.map(arr, (w)
-> S(w).capitalize().s; ).join(', ') str += ' like Ruby’; S(str).pad(15, '-');
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
Benefits
One dependency <script src="/es5shims.js"/> <script src="/underscore-1.3.min.js"/> <script src="/stringjs-0.9.9.js"/> <script
src="/momentjs-1.5.1.js"/> <script src="/custom_functions.js"/>
One dependency <script src="/es5shims.js"/> <script src="/underscore-1.3.min.js"/> <script src="/stringjs-0.9.9.js"/> <script
src="/momentjs-1.5.1.js"/> <script src="/custom_functions.js"/> <script src="/ruby.js">
One API _.map([], (w) -> ) _.chain(arr).(...).value() S("foo").capitalize().s
moment().format('L')
One API R( [1] ).map().to_native() R( [2] ).map().reject().to_native()
R("foo").capitalize().to_native() R(new Date(…)).strftime(“%y-%m-%d”)
One chain arr = ['looks', 'feels', 'acts'] str =
_.map(arr, (w) -> S(w).capitalize().s ).join(', ’) str += " not like Ruby” S(str).pad(str, 35, '-').s
One chain arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-')
One documentaMon
One documentaMon
20 kbytes minified and gzipped
It scales
Dual-‐license • AGPL • Commercial license
Booh
Booh
Should I open source it?
None
DO IT
RubyJS is now MIT License
Happy hacking
Roadmap • Move from CoffeeScript to JavaScript •
RubyJS corelib – Time, Hash, Date • RubyJS corelib-‐lite – remove some rubyisms – simplify
RubyJS.org twi5er.com/hasclass