Posted By

reboltutorial on 04/23/10


Tagged

REBOL


Versions (?)

oop


 / Published in: R
 

URL: http://reboltutorial.com

  1. Rebol []
  2.  
  3. Unprotect 'Class
  4. Class: func['Class Body [block!]][
  5. Type: to-word Class
  6. unprotect Type
  7. set Type Make Object! Body
  8. Protect Type
  9. get Type
  10. ]
  11. Protect 'Class
  12.  
  13. Unprotect 'new
  14. new: func[&Class [Object!] '&Param1 [word! block! unset!] '&Param2 [word! block! unset!]
  15. /local Param-Block ObjName class action
  16. ][
  17. Param-Block: none
  18. ObjName: none
  19.  
  20. Class: &Class
  21. if/else value? '&Param1 [
  22.  
  23. if (type? &Param1) = Word! [
  24. ObjName: &Param1
  25.  
  26. ]
  27.  
  28. if (type? &Param1) = Block! [
  29. Param-Block: &Param1
  30. ]
  31. ][
  32.  
  33. ]
  34.  
  35. if/else value? '&Param2 [
  36. if (type? &Param2) = block! [
  37. Param-Block: &Param2
  38. ]
  39. ][
  40. ]
  41.  
  42. Constructor: to-word pick pick Class 1 2
  43. Obj: Make Class []
  44.  
  45. if/else not none? Param-Block [
  46. params: copy ""
  47. foreach param Param-Block [
  48. if string? param [
  49. param: rejoin [{"} param {"}]
  50. ]
  51. append params param
  52. append params " "
  53. ]
  54.  
  55. do temp: rejoin [{do get in Obj constructor} { } params]
  56. ][
  57. ;do rejoin [ObjWord "/" constructor "/interactive" ]
  58. action: get in Obj 'interactive
  59. if/else (none? action) [
  60. foreach p skip first obj 1 [
  61. if not (function? get in obj to-word p) [
  62. set in obj to-word p ask rejoin [to-string p ": "]
  63. ]
  64. ]
  65. ][
  66. do action
  67. ]
  68. ]
  69.  
  70. if/else not none? ObjName [
  71. Set ObjName :Obj
  72. ][
  73. Obj
  74. ]
  75.  
  76. ]
  77. protect 'new
  78.  
  79. unprotect 'extend
  80. extend: func['byRefObj [word!] Block [block!] /local Obj][
  81.  
  82. Obj: get byRefObj
  83. if/else (type? Obj) = Object! [
  84. Unprotect byRefObj
  85. Set byRefObj Make Obj Block
  86. ][
  87. print [byRefObj "is not an object." ]
  88. ]
  89. ]
  90. protect 'extend

Report this snippet  

You need to login to post a comment.