Skip to content

Instantly share code, notes, and snippets.

@duckinator
Created November 22, 2009 21:56
Show Gist options
  • Save duckinator/240744 to your computer and use it in GitHub Desktop.
Save duckinator/240744 to your computer and use it in GitHub Desktop.
# encoding: utf-8
module R6rs
module Types
#Scheme booleans are in no way related to ruby booleans.
#For that reason we will make our own class for the scheme
#language for now.
#
#What needs to be done is check if the passed value is one
#of '#t' or '#T', if so it is true, else we are false.
class Boolean
attr_accessor :value
def initialize(val)
# Why is this next line not true when passing a string,
# but line 17 works flawlessly?
if val.is_a? String
puts "STRING"
# Assuming it's a string
self.value = (val.downcase == '#t')
elsif val == true || val == false
# Ruby boolean
self.value = val
else
puts "UNKNOWN"
# Unknown value, lets go with true
self.value = true
end
end
def to_s
self.value ? '#t' : '#f'
end
def ==(obj)
obj.value == self.value
end
end
end
end
[/home/nick/dev/ruby/schemey]$ irb -r scheme/r6rs/load.rb
irb(main):001:0> R6rs::Types::Boolean.new('#t')
UNKNOWN
=> #<R6rs::Types::Boolean:0x000000029d8258 @value=true>
irb(main):002:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment