Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
require_relative "helper"
### Parse the sections of the document into a params dictionary
parser = FormLetter::Parser.new
parser.rewrite(:emails, :deadline)
parser.rewrite(:date) { Date.today.strftime("%b %d, %Y") }
# this would come from a database or other source,
module PrawnCalender
module DocumentExtensions
def calender(*a)
draw CalenderWidget.new, *a
end
end
class CalenderWidget
# ...
end

Establish a quality-centric mindset

Having high quality standards for your project is a matter of practicality, not pride. To understand why, it helps to remember that "bad code" is typically hard to understand, hard to test, hard to change, and hard to reuse. Regardless of how useful your project is to the world right now, these problems will get in the way of its future progress.

Any one of these negative traits of bad code can make a maintainer's job painful, but when you combine all four of them it is like wearing a pair of lead boots while trying to run a marathon. Even if you are capable of supporting your project in its current state, these hindrances will gradually chip away at your ability to be responsive to the needs of your users while simultaneously eating up time and energy that you could be using to improve your project's strengths rather than fighting against its weaknesses. Once you head down this road, your project stops being fun to work on, and starts feeling more like a burden.

Once

module Greeter
def greet(name)
"HELLO, #{Name.normalize(name)}!"
end
module Name
def self.normalize(name)
name.strip.upcase
end
end
Greeter = Object.new
class << Greeter
def greet(name)
"HELLO, #{normalize(name)}!"
end
private
def normalize(name)
Hello Practicing Rubyist!
This is just a quick question for you about something I'm working on.
It should only take you a few seconds to answer, so please give
me feedback if you can.
I'm currently experimenting with the idea of building self-guided
courses for Practicing Ruby's readers, which will consist of
recommended readings from our archives as well as from
around the web, practice exercises, discussion questions,
class Proxy
def initialize(document, style)
@document = document
@style = style
end
def text(string, params)
params[:size] ||= @style[:font_size]
params[:color] ||= @style[:font_color]
this_is.a_really_really.really.really.really.really.really.really
.long.method_chain # continuation of the line above
this.is_some +
math.split_across_lines
this(is: "some",
keyword_args: "across lines")
class Parser
rule
string
| a_or_cs abb
| abb
;
a_or_cs
: a_or_cs a_or_c
| a_or_c
;
class Parser
rule
string
| a_or_cs abb
| abb
;
a_or_cs
: a_or_cs a_or_c
| a_or_c
;