Skip to content

Instantly share code, notes, and snippets.

@brianknapp
Last active December 20, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianknapp/6178930 to your computer and use it in GitHub Desktop.
Save brianknapp/6178930 to your computer and use it in GitHub Desktop.
Playing with basic Obvious ideas in different languages
class Entity
def initialize(input:String)
@data = input
end
def get_output
@data
end
end
class TestAction
def execute(input:String)
entity = Entity.new(input)
ConsolePlug.new.save entity.get_output
true
end
end
interface Contract do
def save(data:String):boolean; end
end
class ConsolePlug implements Contract
def save(data:String)
puts "console plug:"
puts data
true
end
end
action = TestAction.new
action.execute "hello world"
require 'obvious'
class Entity < Obvious::Entity
value :data, String
end
class TestAction
include Obvious::Obj
define :execute, with_data: [:data, String] do |input|
entity = Entity.new input
ConsolePlug.new.save entity.to_hash
end
end
class TestContract < Contract
contract_for :save, {
:input => Entity.shape,
:output => true
}
end
class ConsolePlug < TestContract
def save input
puts "console plug:"
puts input[:data]
true
end
end
action = TestAction.new
action.execute with_data: "hello world"
class Entity(input: String) {
def data = input
}
class TestAction {
def execute(with_input:String) = {
val input = with_input
val e = new Entity(input)
val cp = new ConsolePlug
cp.save(e.data)
}
}
trait Contract {
def save(data:String)
}
class ConsolePlug extends Contract {
def save(data:String) = {
println("Console plug")
println(data)
}
}
object HelloWorld {
def main(args: Array[String]) {
val ta = new TestAction
ta.execute(with_input: "hello world")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment