Last active
December 20, 2015 18:49
-
-
Save brianknapp/6178930 to your computer and use it in GitHub Desktop.
Playing with basic Obvious ideas in different languages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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