Alba: Why, How and What's
So Interesting
౦ژRubyձٞ12 લࡇ
OKURA Masafumi, 2025-01-17
Slide 2
Slide 2 text
self.pretty_print
• Name: OKURA Masafumi
• Work: Freelance web developer
• Activities: Kaigi on Rails, TokyoWomen.rb, Rubygems code reading
club, organizing Regional.rb and the Tokyo Metropolis
Slide 3
Slide 3 text
Agenda
• 0. What is Alba?
• 1. Why did I create Alba?
• 2. How was it achieved?
• 3. What’s so interesting about it?
Slide 4
Slide 4 text
0. What is Alba?
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
What is Alba?
• https://github.com/okuramasafumi/alba
• A JSON serializer for Ruby, JRuby and Truf
fl
eRuby
• Core values: Performance, easy-to-use, feature-rich
• Total download: About 1,350,000
• GitHub Stars: About 960
Alba is one of the
fastest among
other Ruby
implementations
Slide 15
Slide 15 text
Easy-to-use
Slide 16
Slide 16 text
No content
Slide 17
Slide 17 text
Minimal API to serialize objects into JSON
• `attributes` DSL to use underlying object’s attribute directly
• `attribute` DSL to compute the result from object’s attribute
• `root_key` DSL to de
fi
ne root key
• `association` DSL to embed other serializers’ result
Slide 18
Slide 18 text
Feature-rich
Slide 19
Slide 19 text
Advanced features of Alba
• Type support
• “Typelizer” gem adds the ability to generate TypeScript types
• Conditional attributes
• Serializing heterogeneous collections
• Filtering
• etc.
When we want to
do “A”, just write
“A” and it should
work
Slide 30
Slide 30 text
2. How was it
achieved?
Slide 31
Slide 31 text
use case
driven
development
Slide 32
Slide 32 text
use case driven development
• It’s one of the forms of TDD (Test Driven Development)
• Follow these steps:
1. Write use cases as test cases
2. Consider if Alba should support these use cases
3. If yes, implement it