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
600
RubyJS at rubyconf.tw
lightning talk
hasclass
December 07, 2012
Tweet
Share
More Decks by hasclass
See All by hasclass
RubyJS
hasclass
1
220
Other Decks in Programming
See All in Programming
CSC307 Lecture 08
javiergs
PRO
0
330
なぜ宣言的 UI は壊れにくいのか / Why declarative UI is less fragile
uenitty
29
13k
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
1.9k
Async Await: Mastering Python's Time-Bending Tricks - EuroPython2024
yanbo
1
290
大規模マルチテナントを解決するYugabyteDBという選択肢
nnaka2992
1
250
開発部に不満を持っていたCSがエンジニアにジョブチェンしてわかった「勝手に諦めない」ことの大切さ
sakuraikotone
28
16k
Introduction of Happy Eyeballs Version 2 (RFC8305) to the Socket library
coe401_
1
220
Advanced App Shrinking Techniques
cbeyls
2
150
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
今こそ始める、CDKコンストラクトライブラリ開発 ― 入門から実践まで
tmokmss
1
930
リハビリmruby
kishima
1
160
社内 LT 会を発足し、アウトプット文化を醸成させるために考えたこと・やったこと / Starting internal LT meetings and fostering an output culture
mackey0225
3
120
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
24
1.8k
Speed Design
sergeychernyshev
9
270
Building Applications with DynamoDB
mza
89
5.8k
What's new in Ruby 2.0
geeforr
338
31k
Rebuilding a faster, lazier Slack
samanthasiow
78
8.5k
Code Review Best Practice
trishagee
58
16k
KATA
mclloyd
20
13k
4 Signs Your Business is Dying
shpigford
178
21k
Fireside Chat
paigeccino
25
2.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
23
1.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
19k
Ruby is Unlike a Banana
tanoku
96
10k
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