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

#&, #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



1073
1074
1075
# File 'lib/dhall/ast.rb', line 1073

def self.as_dhall
	Builtins[:Natural]
end

Instance Method Details

#*(other) ⇒ Object



1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/dhall/ast.rb', line 1090

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



1081
1082
1083
1084
1085
1086
1087
1088
# File 'lib/dhall/ast.rb', line 1081

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

#===(other) ⇒ Object



1124
1125
1126
# File 'lib/dhall/ast.rb', line 1124

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

#as_jsonObject



1128
1129
1130
# File 'lib/dhall/ast.rb', line 1128

def as_json
	[15, value]
end

#coerce(other) ⇒ Object



1077
1078
1079
# File 'lib/dhall/ast.rb', line 1077

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

#even?Boolean

Returns:

  • (Boolean)


1108
1109
1110
# File 'lib/dhall/ast.rb', line 1108

def even?
	value.even?
end

#odd?Boolean

Returns:

  • (Boolean)


1112
1113
1114
# File 'lib/dhall/ast.rb', line 1112

def odd?
	value.odd?
end

#predObject



1120
1121
1122
# File 'lib/dhall/ast.rb', line 1120

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

#to_iObject



1100
1101
1102
# File 'lib/dhall/ast.rb', line 1100

def to_i
	value
end

#to_sObject



1104
1105
1106
# File 'lib/dhall/ast.rb', line 1104

def to_s
	value.to_s
end

#zero?Boolean

Returns:

  • (Boolean)


1116
1117
1118
# File 'lib/dhall/ast.rb', line 1116

def zero?
	value.zero?
end