Created
August 3, 2019 06:05
-
-
Save notEthan/297243912fcbd07354fc3d48093df12f to your computer and use it in GitHub Desktop.
This file contains 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
# Setup | |
require 'active_record' | |
require 'arms' | |
dbfile = "foos.sqlite3" | |
File.unlink(dbfile) if File.exist?(dbfile) | |
ActiveRecord::Base.establish_connection({ | |
:adapter => "sqlite3", | |
:database => dbfile, | |
}) | |
ActiveRecord::Schema.define do | |
create_table :foos do |table| | |
table.column :preferences, :string | |
end | |
end | |
class Foo < ActiveRecord::Base | |
arms_serialize :preferences, :indifferent_hashes, [YAML, Hash] | |
end | |
# Runtime | |
Foo.create!(preferences: {favorite_animal: 'ocelot'}) | |
foo = Foo.last | |
puts foo.preferences_before_type_cast | |
puts foo.preferences[:favorite_animal] | |
puts foo.preferences['favorite_animal'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment