class Gun
attr_reader :smart_ammo
def initialize(ammo)
@smart_ammo = SmartAmmo.at(ammo)
end
# how it sounds from start to finish
def sound_of_the_whole_nine_yards
module MG_tools
Rof = {:sustained => rand(3..9), :rapid => rand(5..9), :cyclic =>
rand(1..200), :cease => 0}
end
class M249
class Program
{
static void Main(string[] args)
{
Account freddie = new Account(5000000);
// freddie buys a grand piano
freddie.balance = freddie.balance - 500000m;
/// One GBP sterling is worth 1.25 USD.
/// We'd have to change the code to reflect this.
class Program
{
static void Main(string[] args)
{
Account freddie = new Account(5000000);
/// Notice how similar it is to the first example?
/// The code is only changed in one place
/// and the change is propogated everywhere else
class Program
{
static void Main(string[] args)
{
## Apologies for pasting here but Stack overflow formatting is simply terrible.
class Person
attr_reader :first_name, :last_name, :separator
def initialize(first_name = nil, last_name = nil, separator = nil)
@first_name = set_first_name(first_name)
@last_name = set_last_name(last_name)
@separator = set_separator(separator)
# consider this person class:
class Person
attr_reader :data
def initialize(data)
@data = data
end
end
# let's count the changes: 6 changes were made
# because we changed the data structure
p = Person.new({age: 20, weight: 30})
age = p.data[:age]
weight = p.data[:weight]
p1 = Person.new({age: 54, weight: 144})
p1_age = p1.data[:age]
p1_weight = p1.data[:weight]
# consider this person class:
class Person
attr_reader :age, :weight
def initialize(data)
@age = data[0]
@weight = data[1]
end
end
# consider the situation where the boss
# required you to use a hash.
# notice how many changes are made:
# just two. This means the code is
# much easier to maintain and easier
# to subsequently change. Because you will
# only be making those changes in a few places
# vs changing everything everywhere!