Skip to content

Instantly share code, notes, and snippets.

View mayra-cabrera's full-sized avatar
💃
Nothing to do here. Go to https://gitlab.com/mayra-cabrera instead

Mayra Cabrera mayra-cabrera

💃
Nothing to do here. Go to https://gitlab.com/mayra-cabrera instead
View GitHub Profile
@mayra-cabrera
mayra-cabrera / exercise-slices.go
Created October 23, 2015 03:27
Exercise slices from golang tour
package main
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
z := make([][]uint8, dy)
for i := range z {
z[i] = make([]uint8, dx)
for j := range z[i]{
z[i][j] = uint8(i^j+(i+j)/2)
class User
has_many :departments
def department_name
departaments.join(",")
end
end
def user_info(user)
"Name: #{user.name}. Dept: #{user.department_name}"
class User
delegate :name, to: :department, prefix: true, allow_nil: true
# ...
end
def user_info(user)
"Name: #{user.name}. Dept: #{user.department_name}"
end
def user_info(user)
"Name: #{user.name}. Dept: #{user.departments.map(&:name).join(",")}"
end
def user_info(user)
"Name: #{user.name}. Boss: #{user.department.try(:head).try(:name)}"
end
def user_info(user)
"Name: #{user.name}. Dept: #{user.department.try(:name)}"
end
class PostDecorator
attr_reader :post
def initialize post
@post = post
end
def is_recent?
published_at > 2.days.ago
end
- if @post_decorator.recent?
= image_tag(@post_decorator.image)
class PostDecorator
attr_reader :post
def initialize post
@post = post
end
def recent?
published_at > 2.days.ago
end