im working through a Rails udemy course and were touching on the part of just ruby right now (Which I have NO experience with so this is all new to me).
In this portion were basically taking "permissions" from a permissions file and putting it into a "user json".
require 'json'
class User
attr_accessor :email, :name, :permissions
def initialize(*args)
@email = args[0]
@name = args[1]
@permissions = User.permissions_from_template
end
def self.permissions_from_template
file = File.read 'user_permissions_template.json'
JSON.load(file, nil, symbolize_names: true)
end
def save
self_json = {email: @email, name: @name, permissions: @permissions}.to_json
open('users.json', 'a') do |file|
file.puts self_json
end
end
end
There is a simple runner.rb
file which creates the user and initializes it, thats not my question though. Basically my question is the self_json = {email: @email, name: @name, permissions: @permissions}.to_json
Ive read the to_json
API and it's simple enough, but every example of a ruby object i've seen looks like this: {:email => @email, :name => @name, :permissions => @permissions}
except replace the @
symbols with "strings"
Im getting confused between the variable types of @variable
and :variable
.
Are we not using :var => @whatever
since were using @
variables or?