Examples Using Custom Components
This page demonstrates the custom components created for the oxidize.rb documentation.
Language-Specific Callouts
Use these callouts to highlight language-specific information:
Ruby
This is a Ruby-specific callout that uses the custom component. It's styled with Ruby's brand color.
class Greeter
def initialize(name)
@name = name
end
def greet
"Hello, #{@name}!"
end
end
Rust Implementation
This is a Rust-specific callout with a custom title. It's styled with Rust's brand color.
struct Greeter {
name: String,
}
impl Greeter {
fn new(name: String) -> Self {
Greeter { name }
}
fn greet(&self) -> String {
format!("Hello, {}!", self.name)
}
}
Code Comparison
The CodeComparison
component allows you to show equivalent Ruby and Rust code side-by-side:
```ruby
class Point
attr_reader :x, :y
def initialize(x, y)
@x = x
@y = y
end
def distance_from_origin
Math.sqrt(x**2 + y**2)
end
end
```
```rust
struct Point {
x: f64,
y: f64,
}
impl Point {
fn new(x: f64, y: f64) -> Self {
Point { x, y }
}
fn distance_from_origin(&self) -> f64 {
(self.x.powi(2) + self.y.powi(2)).sqrt()
}
}
```
These components make it easier to create consistent, well-designed documentation that highlights the relationship between Ruby and Rust code.