Last active
November 21, 2015 01:48
-
-
Save rsutphin/d4bf91bef5f24b7bc3d9 to your computer and use it in GitHub Desktop.
Revisions
-
rsutphin revised this gist
Nov 21, 2015 . No changes.There are no files selected for viewing
-
rsutphin created this gist
Nov 20, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ source 'https://rubygems.org' gem 'cancancan' 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ require 'cancan' Hat = Struct.new(:color) class MyAbility include CanCan::Ability def initialize can :see, Hat, color: "red" end end # --- ability = MyAbility.new if ability.can?(:see, Hat.new("red")) $stderr.puts "✅ You can see a particular red hat, as expected" else $stderr.puts "❌ You can't see a particular red hat. Weird." end if ability.can?(:see, Hat.new("blue")) $stderr.puts "❌ You can see a particular blue hat. That shouldn't happen." else $stderr.puts "✅ You can't see a particular blue hat. Good." end if ability.can?(:see, Hat, color: "red") $stderr.puts "✅ You can see any red hat, as expected" else $stderr.puts "❌ You can't see any red hat. Weird." end if ability.can?(:see, Hat, color: "blue") $stderr.puts "❌ You can see any blue hat. That shouldn't happen." else $stderr.puts "✅ You can't see any blue hat. Good." end if ability.can?(:see, Hat) $stderr.puts "❌ You can see any hat. That shouldn't happen." else $stderr.puts "✅ You can't see just any hat. Good." end