Class: Dhall::Natural

Inherits:
Expression show all
Defined in:
lib/dhall/ast.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #annotate, #as_dhall, #cache_key, #call, #concat, decode, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #shift, #slice, #substitute, #to_binary, #to_cbor, #to_proc, #|

Class Method Details

.as_dhallObject



1122
1123
1124
# File 'lib/dhall/ast.rb', line 1122

def self.as_dhall
	Builtins[:Natural]
end

Instance Method Details

#*(other) ⇒ Object



1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/dhall/ast.rb', line 1139

def *(other)
	other = other.as_dhall
	return self if zero?
	if other.is_a?(Natural)
		with(value: value * other.value)
	else
		super
	end
end

#+(other) ⇒ Object



1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/dhall/ast.rb', line 1130

def +(other)
	other = other.as_dhall
	if other.is_a?(Natural)
		with(value: value + other.value)
	else
		super
	end
end

#===(other) ⇒ Object



1173
1174
1175
# File 'lib/dhall/ast.rb', line 1173

def ===(other)
	self == other || value === other
end

#as_jsonObject



1177
1178
1179
# File 'lib/dhall/ast.rb', line 1177

def as_json
	[15, value]
end

#coerce(other) ⇒ Object



1126
1127
1128
# File 'lib/dhall/ast.rb', line 1126

def coerce(other)
	[other.as_dhall, self]
end

#even?Boolean

Returns:

  • (Boolean)


1157
1158
1159
# File 'lib/dhall/ast.rb', line 1157

def even?
	value.even?
end

#odd?Boolean

Returns:

  • (Boolean)


1161
1162
1163
# File 'lib/dhall/ast.rb', line 1161

def odd?
	value.odd?
end

#predObject



1169
1170
1171
# File 'lib/dhall/ast.rb', line 1169

def pred
	with(value: [0, value - 1].max)
end

#to_iObject



1149
1150
1151
# File 'lib/dhall/ast.rb', line 1149

def to_i
	value
end

#to_sObject



1153
1154
1155
# File 'lib/dhall/ast.rb', line 1153

def to_s
	value.to_s
end

#zero?Boolean

Returns:

  • (Boolean)


1165
1166
1167
# File 'lib/dhall/ast.rb', line 1165

def zero?
	value.zero?
end