Skip to content

Instantly share code, notes, and snippets.

@moonglum
Created November 17, 2012 09:33
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 moonglum/4094497 to your computer and use it in GitHub Desktop.
Save moonglum/4094497 to your computer and use it in GitHub Desktop.
A small example for Arrays in Ashikawa::AR
require "ashikawa-ar"
Ashikawa::AR.setup :default, "127.0.0.1:8529"
class MyFineModel
include Ashikawa::AR::Model
attribute :name
# This is where the magic happens!
attribute :my_strings, Array[String]
end
# Let's delete the old versions. I want this to run multiple times!
MyFineModel.all.each { |a| a.delete }
# Create a new MyFineModel with an Array
a = MyFineModel.new name: "Nice name", my_strings: ["a", "b"]
p a.my_strings
a.my_strings << "c"
p a.my_strings
# Save it to the database
a.save
# Find it again. Just to show that it works when you read it
# back from the database :)
b = MyFineModel.first_example name: "Nice name"
p b.my_strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment