Module: HDLRuby::High::HmetaControl
- Included in:
- Scope
- Defined in:
- lib/HDLRuby/hruby_high.rb
Overview
Module adding metaprogramming capabilities to control statements.
Instance Method Summary collapse
-
#metacase(value, &ruby_block) ⇒ Object
Adds meta programming capability to a case statement.
-
#metaelse(&ruby_block) ⇒ Object
Adds meta programming capability to a else statement.
-
#metaelsif(condition, &ruby_block) ⇒ Object
Adds meta programming capability to a elsif statement.
-
#metaif(condition, &ruby_block) ⇒ Object
Adds meta programming capability to a if statement.
-
#metawhen(match, &ruby_block) ⇒ Object
Adds meta programming capability to a when statement.
Instance Method Details
#metacase(value, &ruby_block) ⇒ Object
Adds meta programming capability to a case statement.
986 987 988 989 990 991 992 993 994 995 |
# File 'lib/HDLRuby/hruby_high.rb', line 986 def (value, &ruby_block) = nil = nil value = value ? 1 : 0 if [true,false,nil].include?(value) if value.respond_to?(:to_i) then = value.to_i return true end return false end |
#metaelse(&ruby_block) ⇒ Object
Adds meta programming capability to a else statement.
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
# File 'lib/HDLRuby/hruby_high.rb', line 1024 def (&ruby_block) ||= nil if then if == :helse then if ruby_block then caught = false HDLRuby::High.top_user.sub do caught = true catch(:HDLRubyThrow) do ruby_block.call caught = false end end end = nil throw(:HDLRubyThrow) if caught end return true end return false end |
#metaelsif(condition, &ruby_block) ⇒ Object
Adds meta programming capability to a elsif statement.
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 |
# File 'lib/HDLRuby/hruby_high.rb', line 956 def (condition, &ruby_block) ||= nil if == :helse then condition = condition ? 1 : 0 if [true,false,nil].include?(condition) # Need to convert the elsif to a if since it is not # compatible with metaprogramming. return :toif unless condition.respond_to?(:to_i) # The hif can be evaluate straight away. Do metaprograming. if condition.to_i != 0 then caught = false HDLRuby::High.top_user.sub do caught = true catch(:HDLRubyThrow) do ruby_block.call caught = false end end = :hif throw(:HDLRubyThrow) if caught else = :helse end return true elsif == :hif return true end return false end |
#metaif(condition, &ruby_block) ⇒ Object
Adds meta programming capability to a if statement.
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
# File 'lib/HDLRuby/hruby_high.rb', line 931 def (condition, &ruby_block) = nil condition = condition ? 1 : 0 if [true,false,nil].include?(condition) if condition.respond_to?(:to_i) then # The hif can be evaluate straight away. Do metaprograming. if condition.to_i != 0 then caught = false HDLRuby::High.top_user.sub do caught = true catch(:HDLRubyThrow) do ruby_block.call caught = false end end = :hif throw(:HDLRubyThrow) if caught else = :helse end return true end return false end |
#metawhen(match, &ruby_block) ⇒ Object
Adds meta programming capability to a when statement.
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 |
# File 'lib/HDLRuby/hruby_high.rb', line 998 def (match, &ruby_block) ||= nil ||= nil match = match ? 1 : 0 if [true,false,nil].include?(match) if and match.respond_to?(:to_i) then # The hwen can be evaluate straight away. Do metaprograming. if == match.to_i then caught = false HDLRuby::High.top_user.sub do caught = true catch(:HDLRubyThrow) do ruby_block.call caught = false end end = :hwhen throw(:HDLRubyThrow) if caught else = :helse end return true end return false end |