Skip to content

Commit

Permalink
update readme style
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Jan 26, 2012
1 parent 901abfe commit f7efca3
Showing 1 changed file with 43 additions and 47 deletions.
90 changes: 43 additions & 47 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ a function, whereas `do something awesome()` calls it. Just like JavaScript.

To create your first object, type this:

````noscript
greeter = Object.clone()
greeter.salute = -> name
("Hello %s!" % name).puts()
end
greeter.salute()
````
greeter = Object.clone()
greeter.salute = -> name
("Hello %s!" % name).puts()
end
greeter.salute()

### Basic data types

Expand All @@ -71,46 +69,44 @@ resolving conflicts by explicitly redefining the conflicting methods.

Create your first trait like this:

````noscript
Runnable = Trait.build("Runnable", {
run: ->
"Running!".puts()
end
})
Serious = Trait.build("Serious", {
run: ->
"Running a serious business.".puts()
end
})
person = Object.clone()
person.age = 20
person.uses(Runnable)
# If we did this now, Noscript would raise a trait conflict error, because
# person cannot have two traits with methods with the same names:
#
# person.uses(Serious)
#
# Instead we have to resolve the conflict defining the #run method on the host.
person.run = ->
if @age > 30
@Serious run()
else
@Runnable run()
end
end
person.uses(Serious)
person.run()
# => Outputs "Running!"
person.age = 35
person.run()
# => Outputs "Running a serious business."
````
Runnable = Trait.build("Runnable", {
run: ->
"Running!".puts()
end
})

Serious = Trait.build("Serious", {
run: ->
"Running a serious business.".puts()
end
})

person = Object.clone()
person.age = 20
person.uses(Runnable)

# If we did this now, Noscript would raise a trait conflict error, because
# person cannot have two traits with methods with the same names:
#
# person.uses(Serious)
#
# Instead we have to resolve the conflict defining the #run method on the host.

person.run = ->
if @age > 30
@Serious run()
else
@Runnable run()
end
end

person.uses(Serious)

person.run()
# => Outputs "Running!"
person.age = 35
person.run()
# => Outputs "Running a serious business."

To read more about how traits work, read `examples/traits.ns`.

Expand Down

0 comments on commit f7efca3

Please sign in to comment.